The simplest is to use one Custom Field to paste the code and use a Shortcode to make the display in pure HTML.
The post would look like this:
You can use as many shortcodes as you want, just put a unique name to the field name, in my case cod-1
(an arbitrary name).
The Custom Field:
Plugin code:
You’ll always see who says "paste this into the functions.php file of Theme";
it’s wrong, make your own plugin, no problem that has 20 lines.
<?php
/**
* Plugin Name: (SOpt) Shortcode para código HTML
* Plugin URI: /a/86941/201
* Version: 1.0
* Author: brasofilo
*/
add_shortcode( 'codigo', 'shortcode_sopt_83496' );
function shortcode_sopt_83496( $atts )
{
global $post;
// field não definido, não faz nada
if ( !isset( $atts['field'] ) )
return '';
// pega valor do custom field no atributo "field" do shortcode
$code = get_post_meta( $post->ID, $atts['field'], true );
// envelopa o código na tag <pre>, estilizar a classe com CSS
return sprintf(
'<pre class="codigo-front">%s</pre>',
htmlentities( $code, ENT_QUOTES )
);
}
Upshot:
You can use a plugin like Advanced Custom Fields to interface to Cfs instead of the default WP.
Pro HTML, you do not escape from having to escape the characters. You can do this manually (which will be a mess), or use something ready to make the escape for you, and then you glue the result in the post and send bullet. Another solution would be to use a wp filter to do this for you (I will study this option further). A third way is to use something like Prism.js http://prismjs.com/
– Caio Felipe Pereira