Skip to content

Instantly share code, notes, and snippets.

@mattiasghodsian
Last active April 28, 2023 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattiasghodsian/feb0d403566c9f314cd8dbf162319027 to your computer and use it in GitHub Desktop.
Save mattiasghodsian/feb0d403566c9f314cd8dbf162319027 to your computer and use it in GitHub Desktop.
[Wordpress] Show/hide content with shortcodes
/**
* 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