1

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!!

  • 1
    You can run any PHP you want inside the shortcode callback. Please post that code. – s_ha_dum Mar 28 '14 at 15:12
0

You can capture the list in a variable, rather than echo it:

$list =
    '<ul class="strong">
        <li>' . get_field( 'highlights_list_item#1' ) . '</li>
        <li>' . get_field( 'highlights_list_item#2' ) . '</li>
    </ul>';

echo do_shortcode( '[one_half]' . $list . '[/one_half]' );

Note the use of get_field() rather than the_field(), which returns a custom field value as opposed to displaying it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.