Use “do_shortcode” in a WordPress plugin is not working

I have this plugin installed on my WordPress:
http://wordpress.org/plugins/put/

I’m trying to make a plugin that uses the UI Tabs plugin inside my own plugin.

Read More

My plugin code so far:

function load_jquery(){
    echo '<link rel='stylesheet' id='jquery-ui-tabs-css'  href='http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/smoothness/jquery-ui.css?ver=1.9.2' type='text/css' media='all' />';
}

add_action('wp_head','load_jquery');

function print_tabs(){
    echo do_shortcode('[tab name="Tab"]-[/tab]');
    echo do_shortcode('[end_tabset]');
}

add_shortcode('print_tabs', 'print_tabs');

Now if I use the [print_tabs] shortcode in a new page, it should look like this:
http://img835.imageshack.us/img835/4905/workingp.png

But it’s not working, and it looks like this:
http://imageshack.us/a/img62/9772/notworkingm.png

What could be the problem here?

Related posts

Leave a Reply

1 comment

  1. The problem, from what I can see in put.php in the Post UI Tabs plugin is that the shortcodes are only added during the “the_content” filter in a function called “on_the_content”.

    add_filter( 'the_content',        array( $this, 'on_the_content' ), 7 ); // Priority 7 - before wpautop
    

    (line 96 of put.php)

    And that function looks like:

        public function on_the_content( $content ) {
    
        $this->has_tabs = (bool) apply_filters( 'put_decide_has_tabs', $this->has_tabs );
    
        if( !$this->has_tabs )
            return $content;
    
        global $shortcode_tags;
    
        // Backup current registered shortcodes and clear them all out
        $orig_shortcode_tags = $shortcode_tags;
        $shortcode_tags = array();
    
        add_shortcode( 'tab',        array( $this, 'on_tab_shortcode' ) );
        add_shortcode( 'end_tabset', array( $this, 'on_tab_end_shortcode' ) );
    
        // Do the shortcode(only the tab shortcode is registered at this point)
        $content = do_shortcode( $content );
    
        // Put the original shortcodes back
        $shortcode_tags = $orig_shortcode_tags;
    
        return $content;
    }
    

    (starting at line 118 of put.php)

    So, given how this plugin is written by modifying the content with a filter which in turn adds the shortcodes when that filter is run, what you’re seeing is probably happening because when you call “do_shortcode” those shortcodes don’t actually exist.

    What echoing do_shortcode is doing then, is just coughing up the text.

    Unfortunately, because of the way the Post UI Tabs plugin is written, you may not be able to do what you’re trying to do.