First of all, your shortcode usage code is incorrect, correct code is:
echo do_shortcode('[loginout_button]');
Now, if you want to echo the login/logout button only when user is not logged in, you can use the function is_user_logged_in()
. There are two ways to do this
1). Conditional logic inside your shortcode.
add_shortcode('loginout_button','add_loginout_button');
function add_loginout_button() {
if ( is_user_logged_in() ) {
return '<div style="text-align:center;background-color:#7114B7;padding:15px;border-radius:50px;margin:20px;"><a href="">LOGIN/REGISTER</a></div>';
}
return false;
}
This is the recommended way because you can use the shortcode anywhere and get the expected result.
2) Wrap your shortcode usage code in the conditional tag
if ( is_user_logged_in() ) {
echo do_shortcode('[loginout_button]');
}
Related Posts:
- do_shortcode() doesn’t work if shortcode contained in variable, works if shortcode passed as string
- Plugin shortcode won’t work on a custom template file [closed]
- Where to find the code used to render a page that has a shortcode and a template defined?
- How to use template inside plugin shortcode with variables for big HTML code
- how to display a template.php in a shortcode
- How to check if short code is present in template?
- WP Customer Reviews call short code on another page [closed]
- Display HTML5 jQuery Audio Player On Front Page
- Is there a WordPress plugin that registers a plugin file as a custom page template?
- Is it possible to define a template for a custom post type within a plugin independent of the active theme?
- Checking if an attribute exists in a shortcode
- Ways to have multiple front-page.php templates that can be swapped out?
- All shortcodes not working on custom theme
- enqueue script only if it is not already enqueue
- Shortcode output appears before post body [duplicate]
- How to parse nested shortcodes?
- How to call shortcode function directly and pass $atts
- change plugin shortcode function [closed]
- Use touch_time() on front-end form via plugin
- Dynamic HTML not displaying at respective place
- Plugin form unable to process
- How do I add a template to a theme using a plugin?
- Short code for Venues
- Frontend editing, Frontend user dashboard
- Shortcode doesn’t work if I directly paste its function in a template file?
- How to enqueue a theme style-sheet to my admin settings page?
- Pass variable to nested shortcode
- How to Include a Loop Template File in a Plugin
- How to get the HTML until ?
- How to generate CSS from a shortcode within a plugin
- Prevent shortcode from being wrapped in tags
- How to remove html code in excel downloads using phpspreadsheet with wordpress plugins shortcode
- Should I fetch the data managed by a plugin by using its APIs or WordPress APIs?
- Plugin Handle URL With Custom Theme
- How to put JQuery/Ajax inside shortcode?
- Snippets: is it better to add them in functions.php or make site-specific plugins?
- Can someone please tell me what is wrong with my plugin?
- Trouble with editing template for “List category posts” plugin
- WordPress function not being called from jQuery method
- Plugin-generated pages use Not Found or Pages Archive templates?
- Facebook Messager Plugin
- Making sure that a plugin’s scripts and stylesheets are included for dynamicaly loaded content
- How WordPress is able to change locale without using setlocale
- Inject HTML meta tag inside wordpress tag using add_shortcode
- Is there any hook for theme activation ? or something similar?
- Use $_GET inside a shortcode print empty Array
- How can I use a file in my plugin as a replacement for single.php on custom-post-type query?
- Render Modula Plugin Shortcode On Ajax Request
- Shortcode to update user meta
- How to add a dvi tag to a shortcode then change a generated text using jQuery
- Shortcode not working after move wordpress website files
- Shortcode not getting replaced
- How do I override plugin templates and stylesheets?
- Return multiple values in a shortcode attribute
- Shortcode Attributes to Return different $_POST
- How to change shortcode’s default theme?
- Get param from shortcode in plugin function
- Loop returns the current page’s permalink and guid instead of the post in the loop
- Inserting shortcode in href – any ideas or workarounds?
- Should meta boxes for specific pages be save in their own plugins?
- Ajax Call in page theme not working?
- Load CSS files in header of Bones theme?
- Prevent plug-in scripts on a specific template?
- Filters on the_content with plugins, pages and shortcode
- Which is a better practice when writing shortcodes: pack lots of configuration parameters or just give an id?
- Show Homepage (only) Hits Count
- Help understanding dynamic endpoints based on where a shortcode is used
- WoCommerce Cart is not showing pricing
- How do I use a plugin’s shortcode attribute value in another function?
- WordPress hierarchy clarification, does post_type_archive take precedence over taxonomy-term archive?
- Shortcode show error while editing post
- Image path in childs theme
- Get Shortcode output to database for static post_content
- What are the disadvantages of using template_redirect for restrictions
- How to prevent redoing get_posts queries and make results available to other scripts?
- Call function with button and return response
- How to use plugin’s shortcode in custom design? [closed]
- Page takes on two different formats
- WP Plugin CSS not being applied to page
- Why is WP template_include overwritting all templates rather than specified page?
- Sanitize AROUND shortcode
- Multiple calling javascript from shortcode in one page
- How to pass value to a plugins shortcode?
- Adding a custom page template to a plugin generated page
- History of page, interval of years
- How to add dynamic content to posts page, archive, taxonomies, search, author, etc?
- Find all strings between an enclosing shortcode
- Is there a function to search for a wildcard value when calling a shortcode?
- Multiple level shortcodes
- How to load a plugin when doing an Ajax call? [duplicate]
- Is it right way to create shortcode?
- Is there any simple wordpress search template that works with existing searchforms?
- Trying to override/intercept a PhotoMosaic gallery link in WordPress using jQuery
- Creating Features List in WordPress Post
- Divi Template A Few Questions
- I am experiencing difficulty fulfilling client request
- My Blog page ( posts page ) theme isn’t changing with the new theme [closed]
- cURL External API request displays content above other content on page
- Is there a plugin or another way that can help me find out the underlying files of a page/post? [closed]
- thumbnail_width not working in wordpress most popular post plugin