[英]Using Custom field inside of do_shortcode(); to use short-code explicitly within the PHP | WordPress
I have to use some WordPress short-codes for a project - but I want them in very specific places, and not in the main content.我必须在一个项目中使用一些 WordPress 短代码 - 但我希望它们在非常特定的地方,而不是在主要内容中。 I need the client to just put them in specific Custom fields.
我需要客户将它们放在特定的自定义字段中。 Using ACF, I built a text field specifically for this.
使用 ACF,我专门为此构建了一个文本字段。
// normal in-code use
<?php echo do_shortcode('[example_shortcode]'); ?>
// ACF field
<?php the_field('my_main_shortcode'); ?>
// ACF field in the do_shorcode
<?php echo do_shortcode( the_field('my_main_shortcode') ); ?>
This renders out [example_shortcode]
on the page instead of what I would expect.这会在页面上呈现
[example_shortcode]
而不是我所期望的。
I'm guessing this is a standard PHP thing - and I don't know how to escape or concatenate it properly.我猜这是一个标准的 PHP 东西 - 我不知道如何正确地转义或连接它。 EDIT - below using
get_fields
gets me closer...编辑 - 下面使用
get_fields
让我更接近......
THEN... with a more complex short-code然后...使用更复杂的短代码
<?php echo do_shortcode( '[tf_listview imagesize="medium1" exclude="calendar-link,list-view-title" dateformat="D n.j"]' ); ?>
It breaks somethings like the image by adding ""
- which could totally be the way the short-code was written / but basically - I haven't found a solution to using a short-code in a custom field like this.它通过添加
""
破坏图像之类的东西 - 这可能完全是短代码的编写方式/但基本上 - 我还没有找到在这样的自定义字段中使用短代码的解决方案。
Bottom line,底线,
I'd like to write: <?php shit_out('my_annoying_shortcode'); ?>
我想写:
<?php shit_out('my_annoying_shortcode'); ?>
<?php shit_out('my_annoying_shortcode'); ?>
Or something as close to that as possible.或者尽可能接近的东西。 AND have it actually work.
并让它真正起作用。
Can anyone give me some more direction?谁能给我更多的方向?
由于您使用的是echo
,您需要使用get_field()
,它return
自定义元值:
<?php echo do_shortcode( get_field('my_main_shortcode') ); ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.