WordPress 登录才能查看网站内容,未登录就跳转到登录页面,有这样需求的人还不少,有的可能是资料类什么的,实现代码很简单,找一个全站一定会执行的钩子即可,荒岛本次带来 WordPress 内容添加登录后查看教程,只要将下面的代码添加到主题的「functions.php」文件即可。
// 荒岛一座藏有宝藏的小岛 add_filter('the_content','user_only'); function user_only($text) { global $post; $user_only; $user_only = get_post_meta($post->ID,'user_only',true); if($user_only) { global $user_ID; if(!$user_ID) { $redirect = urlencode(get_permalink($post->ID)); $text = ' <div class="reply-read"> <div class="reply-ts"> <div class="read-sm"><i class="be be-info"></i>' . sprintf(__( '荒岛提示', 'begin' )) . '</div> <div class="read-sm"><i class="be be-loader"></i>' . sprintf(__( '此宝藏需要 登录后查看', 'begin' )) . '</div> </div> <div class="read-pl"><a href="#login" class="flatbtn show-layer" data-show-layer="login-layer" role="button"><i class="be be-timerauto"></i>' . sprintf(__( '登录', 'begin' )) . '</a></div> <div class="clear"></div> </div>'; } } return $text; }宝藏内容来自荒岛-https://x-imagine.com/wordpress-log-in-to-view-the-content.html宝藏内容来自荒岛-https://x-imagine.com/wordpress-log-in-to-view-the-content.html
请按「Ctrl+D」收藏荒岛分享给好友,如您发现本文教程或宝藏链接已失效,请联系站长修正!
荒岛公众号
扫一扫关注

HDsoft27
公众号ID已复制,前往微信关注...
荒岛哔哩姬
扫一扫关注

ximagine
哔哩姬ID已复制,前往B站关注...