Display codes on the front end without being executed by Edit Post

2

I need my front to present codes and scripts without them running POSTS. Is there any plugin for this? I've used <pre></pre> , but HTML tags still run.

See the image below front . There is a green frame because the HTML has been run, I do not want this to happen . And below the JavaScript code, which correctly displays how it should be:

    
asked by anonymous 31.08.2015 / 17:02

1 answer

2

The simplest is to use a 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 for field name , in my example cod-1 (an arbitrary name).

Custom Field :

Plugin code :
Always see who says "paste this into the functions.php file of the theme" ,
is wrong, make your own plugin , no problem with 20 lines.

<?php
/**
 * Plugin Name: (SOpt) Shortcode para código HTML
 * Plugin URI: http://pt.stackoverflow.com/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 )
    );
}

Result :

You can use a plugin like Advanced Custom Fields to interface for the CFs instead of the WP default

    
15.09.2015 / 04:27