Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

DigitalFormula on "How to add shortcodes to PHP namespace"

$
0
0

Hi all,

All my theme and plugin classes are part of my custom namespace, except for the shortcodes.

The classes have standard PHP __construct() methods that call methods like register_nav_menu(), for example. They work fine.

However, when I modify my shortcode file so that it's part of my namespace and call add_shortcode() in the constructor, the shortcodes no longer work - they just display the [shortcode params=""] markup. If the file isn't part of the namespace and I call add_shortcode() at the end of the file, they work fine.

Here's one of the add_shortcode() calls:

add_shortcode( 'social', 'social_shortcode');

The function's code is like this (with all the main parts removed as they aren't relevant):

function social_shortcode( $atts )
{
   /* do shortcode stuff here */
}

Is there a special way of calling add_shortcode() when the file is part of a namespace? If not, what am I doing wrong?

I've selected 3.7.1 as the WP version, although I'm using 3.8-beta1. The results are the same if I test the code on a production 3.7.1 site, though.


Viewing all articles
Browse latest Browse all 8245

Trending Articles