Adding shortcode outside loops if function exists
-
I am writing a custom feature for my theme to populate the footer with a credit link to my business site for my clients. I’ve been using an admin panel which I enable the credit link so that it shows up.
To keep it simple (since it’s way more complicated), I’ve created the follow shortcode:
function add_footer_credit() { return bloginfo( 'name' ).' is maintained by <a href="https://business.com">My Business</a>.'; add_shortcode('footer_credit', 'add_footer_credit');
In the footer.php, I have the following:
<?php if (function_exists('add_footer_credit')) { echo do_shortcode( '[footer_credit]' ); } ?>
Unfortunately, when I don’t have the shortcode activated in my admin panel, the footer still shows
[footer_credit]
. I’d prefer for it to show nothing when the shortcode isn’t activated. Somehow, it’s still showing up even when I haven’t activated it in the admin panel.
- The topic ‘Adding shortcode outside loops if function exists’ is closed to new replies.