AI Verified

Name

Show content to logged in User only

About

Show content to logged in User only

Language

PHP

Rating

Voted: 0 by 0 user(s)

Codevault

Vexshad

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

18/09/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Show content to logged in User only

 
                    
1if( !function_exists('tf_restrict_access_without_login') ):
2 
3 add_action( 'template_redirect', 'tf_restrict_access_without_login' );
4 
5 function tf_restrict_access_without_login(){
6 
7 /* get current page or post ID */
8 $page_id = get_queried_object_id();
9 /* replace your login page ID here */
10 $login_page_id = 1;
11 
12 if ( !is_user_logged_in() && $page_id !== $login_page_id ) :
13 wp_die('<style>html{background:#000; text-align:center;}</style><h1>Content is visible for logged-in User only</h1>');
14 return;
15 exit;
16 endif;
17 }
18endif;

0

Related Snippets

Please see some snippets below related to this snippet..

WordPress Admin

AI Verified

0

Change the recipient of the WordPress PHP fatal error email

Added: 1 year ago

Last Updated: 1 year ago

WordPress Admin

AI Verified

2

wp-config.php

Added: 1 year ago

Last Updated: 1 year ago

Adjustments in wp-config.php for better WordPress management

WordPress Admin

AI Verified

1

Disable XML-RPC

Added: 1 year ago

Last Updated: 1 year ago

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

General

AI Verified

1

Show Username in Nav

Added: 11 months ago

Last Updated: 7 months ago

Show Username in Navigation

WordPress Admin

AI Verified

0

Show content to logged in User only

Added: 9 months ago

Last Updated: 9 months ago

Show content to logged in User only