前言
隐藏文章的部分内容,需要注册登录网站后可见
正文
下面是实现代码和使用方式。
function.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 '<div style="padding: 50px 0px; text-align: center;color: red;font-weight: bolder"> 要查看隐藏内容,请先登录查阅 </div>>';
}
文章内使用
【members_only】
这里的内容只为已登录的用户显示的
【/members_only】
文章内使用【members_only】和【/members_only】隐藏文章内容
PS:【】一定要换成 [] 即可
参考文章
忘了
历史上的今天
© 版权声明