So, I created an events page for my client that holds lots of details about events. We found no particular event plugins to be helpful for their purpose, so I built a a custom template using advanced custom fields. They are very computer illiterate and will need to be entering these events in very frequently. I used a few shortcodes from my theme to create the layout for these pages. Now I want to take basically make the page super simple for them to fill out, like a form, and output the same layout. To so this, I need to code the shortcodes into my template. All of the shortcodes have opening & closing tags, like this:
[one-half] content [/one-half]
I want to put this list (which includes my advanced custom fields), inside the shortcode tags:
<ul class="strong">
<li><?php the_field('highlights_list_item#1'); ?></li>
<li><?php the_field('highlights_list_item#2'); ?></li>
</ul>
All I have found so far (that is helpful) for putting content inside a shortcode, is this:
<?php echo do_shortcode('[one_half]'.$text_to_be_wrapped_in_shortcode.'[/one_half]'); ?>
But how do I put a list inside there? Can I have advanced custom fields inside shortcode tags?
I thought about just styling this to match what the shortcode does, but I’d like to learn this. Also, I have another section that I will have to do the same thing with, but it is a toggle with an advanced custom field paragraph inside of it.
I really appreciate the help!!
You can capture the list in a variable, rather than echo it:
Note the use of
get_field()
rather thanthe_field()
, which returns a custom field value as opposed to displaying it.