admin管理员组文章数量:1123923
I have a custom post type, where one of ACF fields is map (we take google maps ). Currently, we are pasting that in text field, but to work, that must be executed as a shortcode. The problem is, that when pasting to single.php and page.php:
<?php
// Check if the custom field has a value
if (get_field('zemelapis')) {
// Echo the content of the field, this executes the iframe embed
echo do_shortcode(get_field('zemelapis'));
}
?>
nothing happens. Any suggestions?
I have a custom post type, where one of ACF fields is map (we take google maps ). Currently, we are pasting that in text field, but to work, that must be executed as a shortcode. The problem is, that when pasting to single.php and page.php:
<?php
// Check if the custom field has a value
if (get_field('zemelapis')) {
// Echo the content of the field, this executes the iframe embed
echo do_shortcode(get_field('zemelapis'));
}
?>
nothing happens. Any suggestions?
Share Improve this question asked Mar 21, 2024 at 12:06 rimgaudas.jurgaitisrimgaudas.jurgaitis 31 bronze badge 1- Is the result in the field an actual shortcode function? – Tony Djukic Commented Mar 27, 2024 at 14:04
1 Answer
Reset to default 1you are trying to output the value of an ACF field containing an embed code for a Google Map as a shortcode within your WP theme files . If the shortcode is not being executed, the get_field()
function may be returning the raw value of the field rather than parsing it as a shortcode.
Replace your_google_map_shortcode
with the actual shortcode name that you're using for embedding the map.
<?php
// Check if the custom field has a value
if (get_field('zemelapis')) {
// Get the raw value of the field
$field_value = get_field('zemelapis');
// Check if the field value contains a shortcode
if (has_shortcode($field_value, 'your_google_map_shortcode')) {
// Execute the shortcode
echo do_shortcode($field_value);
} else {
// If no shortcode found, output the raw value
echo $field_value;
}
}
?>
本文标签: pluginsExecuting ACF field as a shortcode
版权声明:本文标题:plugins - Executing ACF field as a shortcode 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736607353a1945361.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论