Skip to content

Instantly share code, notes, and snippets.

@ShinichiNishikawa
Forked from wokamoto/gist:11365599
Last active August 29, 2015 14:00
Show Gist options
  • Save ShinichiNishikawa/11371541 to your computer and use it in GitHub Desktop.
Save ShinichiNishikawa/11371541 to your computer and use it in GitHub Desktop.
おかもとさんより
<?php
add_filter( 'the_content', 'my_pre_shortcode', 7 );
function my_pre_shortcode( $content ) {
global $shortcode_tags;
$shortcode_tags_org = $shortcode_tags;
remove_all_shortcodes();
add_shortcode( 'code', 'code_shortcode_handler' );
$content = do_shortcode( $content );
$shortcode_tags = $shortcode_tags_org;
return $content;
}
function code_shortcode_handler( $atts, $content = null ) {
extract(shortcode_atts(array(
'class' => 'code',
'encode' => 'true',
), $atts));
if ( strtolower($encode) === 'true' )
$content = htmlentities( $content, ENT_QUOTES, get_option('blog_charset') );
return sprintf(
'<pre class="%s"><code>%s</code></pre>'."\n\n",
esc_attr( $class ),
esc_html( $content )
);
}
<?php
add_shortcode('code', 'my_shortcode_handler');
function my_shortcode_handler($atts, $content = null) {
extract(shortcode_atts(array(
'class' => 'code',
'encode' => 'true',
), $atts));
if (strtolower($encode) === 'true' || $content != strip_tags($content))
$content = htmlentities($content, ENT_QUOTES, get_option('blog_charset'));
return sprintf(
'<pre class="%s"><code>%s</code></pre>'."\n\n",
esc_attr($class),
esc_html($content),
);
}
@ShinichiNishikawa
Copy link
Author

wokamotoさんのをフォーク。
最終的に、文脈に合わせて関数名の変更と、半角スペースを入れる変更を入れました。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment