• Let me start off by saying that this is a custom plugin. I am doing it for a client so I may not be able to share the source code.

    Basically, I have implemented several shortcodes for this plugin. Individually the shortcodes work great. However, if I add in multiple shortcodes on a single post/page, only the first shortcode works. The other is ignored entirely, or simply shows the text for the shortcode itself (i.e. [my_shortcode] is shown as text).

    I read through the support forums, as well as some bug reports for WordPress and found a bug similar to this reported in a previous version (2.8.x?). The fix was to place a single space in between the shortcodes. I have tried this to no avail.

    I’ve checked my code and rechecked it, though I am yet to come up with a solution. Is this a common issue? Perhaps a bug similar to the one that was reported in an older version of WordPress?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Is it an enclosed shortcode or is it self-closing?

    Thread Starter louis11

    (@louis11)

    The shortcode I am using is based off the foobar shortcode example in the codex. In particular the shortcode takes the following form:

    [my_shortcode]

    Not sure what this type is called.

    Enclosed would be [my_shortcode]Text[/my_shortcode], whereas self-closing would be [my_shortcode]Text. Your issue may be that you didn’t define it correctly.

    Thread Starter louis11

    (@louis11)

    Here’s the code for my shortcode, I more or less copied the example from the codex:

    <?php
    // List links
    function link_list($atts) {
        global $wpdb;
    
        // Defaults for the shortcode
        extract(shortcode_atts(
                array('num' => 100), $atts
        ));
    
        // Get the information from the database
        $table_name = $wpdb -> prefix . "links";
        $links    = $wpdb -> get_results("select * from $table_name where accepted = '1' limit {$num}");
    
        return build_form($links, 'List Plugin');
    }
    
    // Get the newest links from the database
    function link_newest($atts) {
        global $wpdb;
    
        // Defaults for the shortcode
        extract(shortcode_atts(
                array('num' => 25), $atts
        ));
    
        // Get the information from the database
        $table_name = $wpdb -> prefix . "links";
        $links    = $wpdb -> get_results("select * from $table_name where accepted = '1' order by id desc limit {$num}");
    
        return build_form($links, 'List Plugin - Newest links');
    }
    
    // Get the recently visited links from the database
    function link_visited($atts) {
        global $wpdb;
    
        // Defaults for the shortcode
        extract(shortcode_atts(
                array('num' => 25), $atts
        ));
    
        // Get the information from the database
        $table_name = $wpdb -> prefix . "links";
        $links    = $wpdb -> get_results("select * from $table_name where accepted = '1' order by time desc limit {$num}");
    
        return build_form($links, 'List Plugin - Recently Visted links');
    }
    
    // Add the previous functions to the Shortcode
    add_shortcode('newest_links', 'link_newest');
    add_shortcode('visited_links', 'link_visited');
    add_shortcode('list_links', 'link_list');
    ?>

    or on PasteBin: https://pastebin.com/d694ea769

    See anything wrong with that?

    As far as I can tell, no. You may want to try returning something simpler, like a string test to see if it is the shortcodes themselves that are the problem.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘If multiple shortcodes are present, only the first shows’ is closed to new replies.