How To Create Public and Private ShortCodes in WordPress

Add this to your theme’s functions.php file:
Add this to your theme’s functions.php file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/* Add the [private] shortcode. */ add_shortcode( 'private', 'is_user_logged_in_shortcode' ); /* Add the [public] shortcode. */ add_shortcode( 'public', 'is_user_not_logged_in_shortcode' ); function is_user_logged_in_shortcode( $attr, $content = null ) { /* If it is a feed or the user is not logged in, return nothing. */ if ( is_feed() || !is_user_logged_in() || is_null( $content ) ) return ''; /* Return the content. */ return do_shortcode( $content ); } function is_user_not_logged_in_shortcode( $attr, $content = null ) { /* If it is a feed or the user is logged in, return nothing. */ if ( is_feed() || is_user_logged_in() || is_null( $content ) ) return ''; /* Return the content. */ return do_shortcode( $content ); } |
Categories: How-To's, Technology Tags: howto, Members-Only, php, Provate, public, ShortCode, tips, WordPress
|
No comments
S | M | T | W | T | F | S |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Copyright © 2005-2025 Eric Michael Stone | Random Thoughts, Whims and Fancies…. Powered by WordPress