• Resolved webguy262

    (@webguy262)


    I’m trying to add accordions to a single.php template for a custom post.

    I’ve tried
    <?php echo do_shortcode('[accordion]'); ?>
    etc.

    But didn’t work. The opening ‘accordion’ and ‘accordion-item’ got translated to div’s but the closing shortcodes appeared as the shortcode itself. And the accordion did not work.

    I also tried hardcoding the div’s and classes into the template (no shortcodes) and that also did not work.

    I made sure the JS was in the footer by default… and also tried putting it in the head.

    Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author philbuchanan

    (@philbuchanan)

    You need to make sure your entire accordion block is in a single do_shortcode() function. E.g.

    <?php echo do_shortcode('[accordion][accordion-item title="Title goes here"]Content goes here[/accordion-item][/accordion]'); ?>

    I’m also trying to add this but I have complex code in the “Content” section. What am I doing wrong?

    <?php if( get_field('references') ): ?>
          <div class="box_conditions left">
    	<div id="title_references">References</div>
    	   <?php echo do_shortcode('[accordion clicktoclose="true"][accordion-item title="References"]	
    	<?php 
    	// check if the repeater field has rows of data
    	 if( have_rows('references') ):
    	// loop through the rows of data
    	while ( have_rows('references') ) : the_row();?>
    	<div class="col">
    	<div class="cell_ref"><?php the_sub_field('reference_name');?></div>
    	</div>								
    	<?php endwhile;?>
    	<?php else :
    		// no rows found
    	endif; ?>
    	[/accordion-item][/accordion]'); ?>
    	<?php endif; ?>
    • This reply was modified 6 years, 5 months ago by ajroylance.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Accordions in template files?’ is closed to new replies.