我
build my own websiteOften, there are the following two situations where you don't want others to view the website content. 1. A purely personal blog, not wanting to be viewed by others. 2. Certain internal websites, not wanting irrelevant people to access. 3. Special resource sites. So, if your website is built with
WordPressyou can easily achieve the
WordPress Pluginfunctionality through
WordPress login required to view. Below are several plugins shared by Naiba to achieve
WordPress requires registration to view.
Registered Users Only
The Registered Users Only plugin was seen on WP Jianzhan Ba. The plugin's functionality is very simple. After installation and activation, all non-registered/non-logged-in users will be redirected to the login page.

If you wish to allow open registration, then check 'Allow anyone to register'. If you want visitors to temporarily access the website content, then check 'Guest Mode'.
Download LinkForce Login
Force Login is even simpler. After downloading and activating, it directly enables the
full site requires login to viewfunctionality. There is no separate settings page. Activating the plugin requires login to view, deactivating the plugin removes the login requirement to view website content.
Download LinkMy Private Site
My Private Site, this plugin is more suitable for resource marketing websites because, besides redirecting non-logged-in users to the login page, it can also customize the login interface and the registration interface. Furthermore, the most powerful feature of My Private Site is the ability to exclude pages. You can set the homepage to be viewable without login, and you can also add other pages that can be viewed without login. At the same time, if the 'login required to view pages' feature is enabled, it also supports redirecting users to the page they were trying to access before logging in.
Introduction to the Simple Usage of My Private Site:Check 'Private Site' to enable login access. 'Custom Login' is the option for customizing the login page. 'Visible Exclusions' is the option for excluding pages.
Download LinkShow/hide on demand
If you want to set methods to display specific content and hide specific content yourself, you can use
Wicked Block ConditionsIf using code, here is the following:
add_shortcode('hide','loginvisible');
function loginvisible($atts,$content=null){
if(is_user_logged_in() && !is_null($content) && !is_feed())
return $content;
return '';
}Then, in the post, wrap the hidden content with [hide] and [\/hide]. If you only want to simply hide posts from the website homepage or category pages, you can refer to:
How to Hide Specific Posts on WordPress Homepage or Category PagesVisible after entering password
If you want to require a password to view or access WordPress posts, categories, or the entire website, you can see this article:
3 WordPress Plugins That Require a Password to Access the Website_Password to View ContentUsing code to hide categories, visible after login
//template_redirect动作钩子是一定会执行的,所以用这个钩子对全站有效
add_action( 'template_redirect', 'ashuwp_show_only_login', 0 );
function ashuwp_show_only_login(){
//判断登录,about页面就允许访问
if( !is_page('about') && !is_user_logged_in() ){
auth_redirect(); //跳转到登录页面
exit();
}
}If a category directory requires login to be visible, use the following code.
// 首页和指定分类文章可以访问
add_action( 'template_redirect', 'ashuwp_show_only_login', 0 );
function ashuwp_show_only_login(){
//判断登录,只允许访问ID为3和2的分类文章
if( !in_category( array( '3','2' ) ) && !is_home() && !is_user_logged_in() ){
auth_redirect(); //跳转到登录页面
exit();
}
}The exclamation mark before !in_category means 'not,' indicating that if it is not categories with IDs 3 and 2, and not the homepage, and not logged in, then redirect to the login page. Add the code to the theme's functions.php template to take effect. Note that in_category only supports first-level directories; if there are subdirectories, you need to list them all or add the following condition.
if ( ! function_exists( 'post_is_in_descendant_category' ) ) {
function post_is_in_descendant_category( $cats, $_post = null ) {
foreach ( (array) $cats as $cat ) {
// get_term_children() accepts integer ID only
$descendants = get_term_children( (int) $cat, 'category' );
if ( $descendants && in_category( $descendants, $_post ) )
return true;
}
return false;
}
}Then call it like this
Refer toUltimate Plugin
Not satisfied after testing the above methods one by one? I recommend a powerful conditional plugin that Naiba is currently using. [vk-content]

This plugin, named Restrict User Access – Membership Plugin with Force, is very suitable for friends who need multiple conditions but cannot rewrite code themselves.

You can add multiple conditions, then set user groups in Members, set permissions in Capabilities, and save to take effect.
Download Link [\/vk-content]
Comments are closed
The comment function for this article is closed. If you have any questions, please feel free to contact us through other channels.