Skip to content

Instantly share code, notes, and snippets.

@tomoyasu999
Created November 18, 2018 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomoyasu999/a2e60701c61a913b609595a39ce6bc7f to your computer and use it in GitHub Desktop.
Save tomoyasu999/a2e60701c61a913b609595a39ce6bc7f to your computer and use it in GitHub Desktop.
WordpressのカスタムHTMLでPHPを実行するためのコード(子テーマの編集 > functions.php)
/* カスタムhtmlで特定PHPファイルを実行可能にする */
add_filter( 'widget_text', function( $ret ) {
$php_file = 'add-wt-category-head-img';
if( strpos( $ret, '[' . $php_file . ']' ) !== false ) {
add_shortcode( $php_file, function() use ( $php_file ) {
get_template_part( $php_file );
});
ob_start();
do_shortcode( '[' . $php_file . ']' );
$ret = ob_get_clean();
}
return $ret;
}, 99 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment