Created
November 18, 2018 10:45
-
-
Save tomoyasu999/a2e60701c61a913b609595a39ce6bc7f to your computer and use it in GitHub Desktop.
WordpressのカスタムHTMLでPHPを実行するためのコード(子テーマの編集 > functions.php)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* カスタム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