My Private Site Shortcode

Below, you’ll find a detailed guide on how to add the My Private Site Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the My Private Site Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the My Private Site Plugin and the shortcodes it provides:

Plugin Icon
My Private Site

"My Private Site is a WordPress plugin that allows you to make your website private, accessible only by registered users. With jonradio-private-site, ensure your site's exclusive accessibility."

★★★★✩ (75) Active Installs: 20000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [privacy]

My Private Site [privacy] Shortcode

The jonradio-private-site plugin shortcode ‘privacy’ controls content visibility based on user login status. The ‘hide-if’ attribute accepts ‘logged-in’ or ‘logged-out’. Content within the shortcode is hidden if the condition is met. For instance, ‘hide-if=”logged-in”‘ hides the content for logged-in users. Conversely, ‘hide-if=”logged-out”‘ hides content for logged-out users. This allows selective content display, enhancing site personalization.

Shortcode: [privacy]

Parameters

Here is a list of all possible privacy shortcode parameters and attributes:

  • hide-if – controls visibility of content based on user login status

Examples and Usage

Basic example – Show content only to logged-in users

[privacy hide-if="logged-in"]Exclusive content for logged-in users[/privacy]

In the basic example, the shortcode is used to display content only to logged-in users. The ‘hide-if’ attribute is set to ‘logged-in’, which means the content within the shortcode will be hidden if the user is logged in. If the user is not logged in, the content will be displayed.

Advanced examples

Display different messages to logged-in and logged-out users

[privacy hide-if="logged-in"]Welcome, guest! Please log in to see more.[/privacy]
[privacy hide-if="logged-out"]Welcome back, user! Enjoy your exclusive content.[/privacy]

In this advanced example, two instances of the shortcode are used to display different messages to logged-in and logged-out users. The first shortcode hides the message if the user is logged in, effectively showing it only to guests. The second shortcode does the opposite, hiding the message if the user is logged out and thus showing it only to logged-in users.

PHP Function Code

In case you have difficulties debugging what causing issues with [privacy] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'privacy', 'my_private_site_shortcode' );

Shortcode PHP function:

function my_private_site_shortcode( $atts, $content = null ) {
	// HIDE
	if ( isset( $atts['hide-if'] ) ) {
		$condition_to_check = strtolower( $atts['hide-if'] );
		switch ( $condition_to_check ) {
			case 'logged-in':
				if ( is_user_logged_in() ) {
					$content = '';
				}
				break;
			case 'logged-out':
				if ( ! is_user_logged_in() ) {
					$content = '';
				}
				break;
		}
	}

	return $content;
}

Code file location:

jonradio-private-site/jonradio-private-site/jonradio-private-site-admin.php

Conclusion

Now that you’ve learned how to embed the My Private Site Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *