本文最后更新于2022年5月1日,已超过 30 天没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!
首先,打开主题的 functions.php 在最底部添加 下面代码
//WordPress 只允许已登录的用户查看文章内容
add_shortcode( 'members_only', 'members_only_shortcode' );
function members_only_shortcode( $atts, $content = null ){
if ( is_user_logged_in() && !empty( $content ) && !is_feed() ){
return $content;
}
return '<blockquote><p>温馨提示:本处有隐藏内容! <a href="'.wp_login_url( get_permalink() ).'">登录</a> 后即可查看!</p></blockquote>';//此处根据需要修改
}
然后,书写的简代码为下
[members_only]
这里的内容只为已登录的用户显示
[/members_only]
演示
[members_only]
这里的内容只为已登录的用户显示
[/members_only]