php - do_shortcode not working

php – do_shortcode not working

php – do_shortcode not working

[STORE-LOCATOR] is probably not a shortcode in WordPress sense.

I encountered this on different plugin, Stream media player. They use the same syntax as shortcodes, but they are actually not.

Try using:

echo apply_filters( the_content, [STORE-LOCATOR] );

instead of do_shortcode, and see if it helps.

do_shortcode() returns a string.
I get it working by doing:

<?php echo do_shortcode(...); ?>

php – do_shortcode not working

This is specific to the Store Locator plugin, not do_shortcode in general.

apply_filters can be an acceptable workaround for other plugins, but this does not work for Store Locator; you will only see an empty space and some controls. This is because it is looking for that shortcode in the page/post body to determine whether or not to include all of its js references at the top of the page. And without these references, nothing will work. See the sl_head_scripts function in sl-functions.php.

To change this behavior, simply modify that function to match based upon page title instead. In my instance I wanted it only on a shop page, so I commented out the entire $on_sl_page test and replaced it with this:

$on_sl_page = ( strpos($pagename, shop) === 0 );

I then called it from my page with apply_filters as indicated in the other answer:

echo apply_filters( the_content,[STORE-LOCATOR]);

And this appears to work perfectly.

Related posts on PHP  :

Leave a Reply

Your email address will not be published.