最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

advanced custom fields - Can I wrap an unordered list inside a shortcode?

programmeradmin0浏览0评论

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

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

Share Improve this question asked Mar 28, 2014 at 15:01 user49624user49624 112 bronze badges 1
  • 1 You can run any PHP you want inside the shortcode callback. Please post that code. – s_ha_dum Commented Mar 28, 2014 at 15:12
Add a comment  | 

1 Answer 1

Reset to default 1

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.

发布评论

评论列表(0)

  1. 暂无评论