WordPress.org

Ready to get started?Download WordPress

Forums

Plug-in's shortcode works in post but not with do_shortcode (3 posts)

  1. oxfordian3
    Member
    Posted 3 years ago #

    I have started using the Store Locator plug-in (http://www.viadat.com/store-locator/), and it looks very promising.

    I have one problem. If I enter its shortcode ("[STORE-LOCATOR]") in the content of a post/page it is processed correctly. But if I enter it in a custom template with

    <?php echo do_shortcode('[STORE-LOCATOR]'); ?>

    it does not work, and just outputs the [STORE-LOCATOR] text. I found a mention of this same problem on the Stack Overflow tech site, but nowhere else.

    I am able to use do_shortcode with my own custom shortcodes, added in my functions.php.

    I'm not an expert in WP sequencing, but it seems like the plug-in is not loaded/initialized at the time it executes do_shortcode, but is loaded by the time it processes the $content. Is there a way to adjust this?

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    some plugins don't use real shortcode, but some preg-replace to locate and process the stuff within the square brackets.

    'do_shortcode()' will not work in these cases.

    check the plugin code, if this is the case.

    you might be able to find a function to call directly;
    or contact the plugin author.

  3. oxfordian3
    Member
    Posted 3 years ago #

    Thanks for the response. Yes you're right -- I searched the plug-in source code and it is doing custom preg replacement of the tag in the post content (not the template). It also relies on having the tag in the post content so it can detect and insert content to the <head> of the page. It's not doing a real shortcode.

    The plug-in has its own mechanism for skinning, so I'll probably work within that structure instead.

Topic Closed

This topic has been closed to new replies.

About this Topic