Support » Themes and Templates » [Resolved] do_shortcode on closing isn't working

[Resolved] do_shortcode on closing isn't working

  • Marj Wyatt


    I am wondering what I’m doing wrong.

    I’ve found a plugin that will apply accordion styles to content using shortcodes. Here is the link for that plugin:

    For my custom theme project, there are several categories that my client wants to expand to display all the posts in those categories so I would like to use this plugin to accomplish that.

    Since my client will be adding new content after my work is complete, I’ve been trying to work out how to use the do_shortcode function in a custom page template to expand the categories to clickable links.

    Here is a link to the code that I’ve written as a test:

    The code is “almost working” except for the fact that the closing shortcode is displaying as content at the end of the list which is causing the accordion to fail.

    Can anyone help me understand what I’m doing wrong?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Michael


    Forum Moderator

    you possibly need to parse the full shortcode;

    example (untested – make a backup of your existing files before trying):

    <?php $shrt_cd = "[accordion title='Menus & Parties']";
        query_posts( array ( 'category_name' => 'menus-parties' ) );
            $shrt_cd .= '<ul>';
            while (have_posts()) : the_post();
                    $shrt_cd .= '<li><a href="'.get_permalink().'">';
                    $shrt_cd .= get_the_title();
                    $shrt_cd .= '</a></li>';
            $shrt_cd .= '</ul>';
            $shrt_cd .= "[/accordion]";
            echo do_shortcode( $shrt_cd ); ?>
    Marj Wyatt


    Hey Alchymyth …

    That worked great! Thanks so much.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] do_shortcode on closing isn't working’ is closed to new replies.