网站优化

网站优化

Products

当前位置:首页 > 网站优化 >

检查WordPress functions.php中的URL

GG网络技术分享 2025-03-18 16:12 5


问题描述:

I want to restrict access to a specific URL of my WordPress-Site for logged-in users only. So if someone isnt logged in, they should be redirected to homepage.

I guess its working with this code in functions.php

if (!(is_user_logged_in()) && is_page(\'PAGE-ID\')){

wp_redirect( home_url() . \'/login\' );

exit;

}

But unfortunately this site has no Page-ID, so I have to target the URL instead. How can I do this?

图片转代码服务由CSDN问答提供

感谢您的意见,我们尽快改进~

功能建议

我想限制仅对登录用户访问我的WordPress网站的特定网址。 因此,如果有人登录,则应将其重定向到主页。 </ p>

我想它在functions.php </ p>

 中使用此代码if(!(is_user_logged_in())&amp;&amp; is_page(  \'PAGE-ID\')){

wp_redirect(home_url()。\'/ login\');

退出;

}

</ code> </ pre>

但不幸的是这个网站 没有Page-ID,所以我必须改为定位URL。 我该怎么做?</ p>

</ div>

网友观点:

Try like this.

global $post;

$pageUrl = get_permalink($post->ID);

if (!(is_user_logged_in()) && $pageUrl==\'http://yoursiteurl.com/page/\'){

wp_redirect( home_url() . \'/login\' );

exit;

}

标签:

提交需求或反馈

Demand feedback