Shortcodes don't work online

I created some shortcodes which I have include into functions.php

This is the shortcode.php code I have used:

// alert box 
function alertBox($atts, $content = null) {
    extract(shortcode_atts(array(
        "bgcolor" = '#ffffff'
    ), $atts));
    return 'div class="alertBox" style="background:'.$bgcolor.'"'.$content.'/div';
}

add_shortcode("alertbox", "alertBox");

/*** info box ***/
function infoBox($atts, $content = null) {
    extract(shortcode_atts(array(
        "bgcolor" = '#ffffff'
    ), $atts));
    return 'div class="infoBox" style="background:'.$bgcolor.'"'.$content.'/div';
}

add_shortcode("infobox", "infoBox");

All this was included into the functions.php using this line:

include TEMPLATEPATH . '/extras/shortcodes.php';

When working on WAMP (offline) shortcodes work beautifully but online WordPress only spew out the actual tags like this:

[alertbox]Sometext[/alertbox]

I have created many shortcodes, though mostly with copy/paste/refine... Does anyone have an idea as to why this might happen?

Topic offline shortcode Wordpress

Category Web


First, change this:

include TEMPLATEPATH . '/extras/shortcodes.php';

...to this:

include ( TEMPLATEPATH . '/extras/shortcodes.php' );

Second, change TEMPLATEPATH to get_template_directory():

include ( get_template_directory() . '/extras/shortcodes.php' );

(The TEMPLATEPATH and STYLESHEETPATH globals are going away eventually.)

Third, make sure you namespace your function names properly. Function names "alertBox()" and "infoBox()" are far too generic.

Beyond that, we probably need to see your error messages.


Hi sometimes it is a "silly" error . Look at the start of the file - is the bracket "< ? php " correctly entered ? And wherever else you have it?

By the way I always develop and test with wp-debug switched on permanently on my localhost. It is very useful at flushing out errors.

Yea sometimes one has to switch off when playing with someone else's plugin that did not have the same rigour but well worth the effort .

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.