WordPress で、投稿や固定ページの時だけ出力したい(またはしたくない)文書を書くためのショートコード。
functions.php とかに追記してね。
使い方は
[is_singular]投稿や固定ページの時だけ出力したい文章[/is_singular]
または
[is_singular enable=FALSE]投稿や固定ページの時だけ出力したくない文章[/is_singular]
class Is_singular_ShortCode {
function __construct() {
add_shortcode('is_singular', array(&$this, 'Shortcode_Handler'));
}
function Shortcode_Handler($atts, $content = null) {
extract( shortcode_atts( array(
'enable' => TRUE
), $atts) );
$return_text = '';
$enable = (strtolower($enable) === 'false' ? FALSE : TRUE);
if ($enable && is_singular()) {
$return_text = $content;
} else if (!$enable && !is_singular()) {
$return_text = $content;
}
return $return_text;
}
}
new Is_singular_ShortCode();
コメントを残す