在WordPress中,我在函数中使用函数。php仅在用户未登录时不显示某些帖子(按类别):
function my_filter( $content ) {
$categories = array(
\'news\',
\'opinions\',
\'sports\',
\'other\',
);
if ( in_category( $categories ) ) {
if ( is_logged_in() ) {
return $content;
} else {
$content = \'<p>Sorry, this post is only available to members</p> <a href="gateblogs.com/login"> Login </a>\';
return $content;
}
} else {
return $content;
}
}
add_filter( \'the_content\', \'my_filter\' );
我使用一个插件(对我的问题不重要),但基本上,我可以使用https://gateblogs.com/login?redirect_to=https%3A%2F%2Fgateblogs.com%2Ftechnology%2Flinux-tutorials%2Fsending-mail-from-server
成功登录后重定向到页面。如何获取帖子的URL并将其应用到注册链接中。注意:该函数最初来自this question.