Run shortcode before filters

My users post snippets code in comments.
I created a shortcode for this :

function post_codigo($atts,$content=""){

        return '<code>'.$content.'</code>';
}

add_shortcode('codigo','post_codigo');  

Problem is that html gets filtered before its wrapped into the code tags.

I think that if i can get the shortcode run before filters then i can use

function pre_esc_html($content) {
  return preg_replace_callback(
    '#(<code.*?>)(.*?)(</code>)#imsu',
    create_function(
      '$i',
      'return $i[1].esc_html($i[2]).$i[3];'
    ),
    $content
  );
}

add_filter(
  'the_content',
  'pre_esc_html',
  9
);

that i found around here. What you think?

UPDATED: Ok now i changed my shortcode to:

 function post_codigo($atts,$content=""){

            return '<code>'.esc_html($content).'</code>';
    }

    add_shortcode('codigo','post_codigo');

But it still adding

breaks and breaking the whole code into several tags

4 Answers
4

You can filter the array $no_texturize_shortcodes, which is a collection of shortcodes that are excluded from wptexturize. If you do this, everything within [codigo] shortcode tags will not be texturized:

add_filter( 'no_texturize_shortcodes', 'no_texturize_codigo_shortcode' );

function no_texturize_codigo_shortcode( $excluded_shortcodes ) {
    $excluded_shortcodes[] = 'codigo';
    return $excluded_shortcodes;
}

Leave a Comment