Support » Fixing WordPress » 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="">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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • I missed a close bracket in the initial shortcode so don’t pay attention to that. The code works great when activated, I just want to make sure that when NOT activated nothing shows up instead of the [footer_credit] text (meaning it’s not rendering when there’s nothing to render).

    Thanks for the snippet! I’m using this in a theme designed to work with a specific plugin for a client, very helpful. 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding shortcode outside loops if function exists’ is closed to new replies.