我目前正在开发一个插件,其中仅将某些页面限制为登录用户。我的意思是我们在Wordpress中创建的普通页面。
我在网上找到了它,但它似乎对我不起作用。
function check_the_current_page(){
echo $slug = basename(get_permalink());
}
add_action( "init", "check_the_current_page" );
我的另一个选择是检测当前页面ID,如下面的代码所示。屏幕上没有任何内容打印出来,可能是我使用了错误的挂钩或其他东西,有人帮了我
function check_the_current_page(){
global $post;
echo "Post id: ".$post->ID;
}
add_action( "init", "check_the_current_page" );
如果只有我能够在上述情况之一中获得输出,那么这将非常简单,但是现在在这两种情况下屏幕上都没有打印任何内容
Try This Code Work For Me global $post dosent work in init
function check_the_current_page() {
global $post;
echo "Post id: " . $post->ID;
}
add_action( "wp", "check_the_current_page" );
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句