网站首页其他教程文章正文  

在WordPress中设置部分内容仅登录可见的方法

     
一 在functions.php中添加代码

代码如下

/*
* 本站只允许已登录的用户查看文章内容
*/
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 '此部分内容仅登录可见,请先登录,谢谢理解';这儿可以添加你的网站登录链接
}
二 在正文中添加代码

代码如下【要在文本模式中添加】

[/members_only去掉] 删除“去掉”二字

# 上面的代码添加在仅登录可见部分内容之上

# 下面的代码添加在仅登录可见部分内容之下

[/members_only去掉] 删除“去掉”二字

转自:

https://www.pc521.net/article/wordpress-download.html

谢谢分享

     
购买 Google Voice 靓号 / GV 靓号

发表评论