次のコードを機能させようとしています。
if( is_home() ):
echo 'User is on the homepage.';
else:
echo 'User is not on the homepage';
endif;
テーマのヘッダーまたはフッターに配置すると機能しますが、プラグインに配置すると機能しません。私も試してみましたがis_single()、is_page()プラグイン内では機能しません。問題は何ですか?
次のコードを機能させようとしています。
if( is_home() ):
echo 'User is on the homepage.';
else:
echo 'User is not on the homepage';
endif;
テーマのヘッダーまたはフッターに配置すると機能しますが、プラグインに配置すると機能しません。私も試してみましたがis_single()、is_page()プラグイン内では機能しません。問題は何ですか?
is_home()他のいくつかの WP 関数は常に定義されているとは限りません。適切な を使用しhookてコードをインクルードしてみてください。例:
add_action('wp', 'check_home');
// or add_action('init', 'check_home');
function check_home($param)
{
if (is_home()):
echo 'User is on the homepage.';
else:
echo 'User is not on the homepage';
endif;
}
編集:
いずれにせよ、データをエコーしたい場合は、bodyタグ内でフックを使用してください。the_contentフックを使用した例:
add_filter('the_content', 'check_home');
function check_home($content)
{
if (is_home())
$echo = 'User is on the homepage.';
else
$echo = 'User is not on the homepage';
return $echo . '<hr />' . $content;
}