Support » Plugin: Collapse-O-Matic » putting the shortcode into my template

  • Resolved traypup


    Hi there,
    I’ve tried a few different ways and I’m close, but my syntax, I think, is throwing things off. Can someone help me get my code right?

    I put together a FAQ page using Advanced Custom Fields. That bit is working great. Now I want to add in C-o-M so the user can click the titles and show the answers.

    I had this:

    [expand title="<?php the_sub_field('question_title') ?>"]
    <p><?php the_sub_field('question_answer') ?></p>[/expand]')

    and it showed the question titles and answers, but also the brackets and “expand” code, so I realized I needed to call the shortcode first and did this:

    <?php echo do_shortcode('[expand title="<?php the_sub_field('question_title') ?>"]
    <p><?php the_sub_field('question_answer') ?></p>[/expand]') ?>

    And the page is showing the error
    Parse error: syntax error, unexpected T_STRING

    Any suggestions on how to fix?
    Thank you!

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Baden


    you almost have it. Try:

    <?php echo do_shortcode('[expand title="'.the_sub_field('question_title').'"]'.the_sub_field('question_answer').'[/expand]'); ?>

    Please let us know if this works for you.

    Ok, cool, the error message isn’t coming up any more, but I’m still not getting the collapsing functionality. All of the Qs and As are just laid out on the page. But the arrows are clickable and change back and forth between pointing up and down! 🙂

    Plugin Author Baden


    under the plugin option page (Dashboard > Settings > Collapse-O-Matic) check and make sure that the check box for “Shortcode Loads Scripts” is UNchecked.

    For further assistance you will need to share a link so we can trouble shoot further.

    It is unchecked.

    Can I email you a link and login? I have the site hidden at the moment since it’s in development. Thank you!

    Plugin Author Baden


    yes. just be sure to include a link to this thread and shoot it to us info [at] twinpictures [dot] de

    thank you! emails will come from websmith [at] eeep [dot] com

    Plugin Author Baden


    We took a look, and the_sub_field('question_answer') is returning NULL.


    Please verify that the_sub_field('question_answer') is the correct way to call the faq answer.

    Interesting. That is the correct field name. I took a screen shot of the ACF page that shows the fieldnames:

    If you look at the FAQ page (, you’ll see that the contents of that field show up in the page…so I’m not sure how it returns NULL. (Unless I’m not understanding what you’re saying!)

    Do you have any other ideas on this issue?

    It’s fixed. I prevailed upon a colleague to take a look. Here’s what he did:

    Just made a couple of simple changes. You just needed to change “the_sub_field” to “get_sub_field”. The “the_” call will display the information whereas “get_” stores a value which works with the plugin because it’s creating a link from the title.

    I’ve left the title as the_field – however, if you change this to “get_sub_field” it will create the title as a link and move the arrow to the left of the title. It’s up to you I don’t think it effects usability at all.

    I simply deleted


    //var_dump(the_sub_field(‘question_answer’)); //returns null

    echo do_shortcode(‘[expand title=”‘.the_sub_field(‘question_title’).'”]’.the_sub_field(‘question_answer’).'[/expand]’);


    and replaced it with


    //var_dump(the_sub_field(‘question_answer’)); //returns null
    $title = the_sub_field(‘question_title’);
    $answer = get_sub_field(‘question_answer’);

    echo do_shortcode(‘[expand title=”‘ . $title . ‘”]’ . $answer . ‘[/expand]’);


    Plugin Author Baden


    glad you got it working

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘putting the shortcode into my template’ is closed to new replies.