Last active
April 28, 2023 08:38
-
-
Save mattiasghodsian/feb0d403566c9f314cd8dbf162319027 to your computer and use it in GitHub Desktop.
[Wordpress] Show/hide content with shortcodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Title: Shortcode Logged in | |
* Author: Mattias Ghodsian | |
* Description: Shortcodes that works like if statments | |
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian | |
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5 | |
**/ | |
// If logged in | |
function loggedincontent( $atts , $content) | |
{ | |
if ( is_user_logged_in() ) { | |
$content = str_replace(['<br>', '<br />', '<br/>', '\n'], '', $content); | |
echo do_shortcode($content); | |
} | |
} | |
add_shortcode( 'loggedincontent', 'loggedincontent' ); | |
// If not logged in | |
function notloggedincontent( $atts , $content) | |
{ | |
if ( !is_user_logged_in() ) { | |
$content = str_replace(['<br>', '<br />', '<br/>', '\n'], '', $content); | |
echo do_shortcode($content); | |
} | |
} | |
add_shortcode( 'notloggedincontent', 'notloggedincontent' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment