Nested shortcodes possible?
-
Hi there,
Im looking for a way to put a shortcode into my ACF custom field [nested_shortcode] and with Advanced Views Framework im using the ACF shortcode to display my [nested_shortcode] – how is this possible? as of now – im just getting the [nested_shortcode] as text.
Chat GPT has been super unhelpful, maybe you han help me out..
Question:
“can i put a shortcode inside a shortcode , in the WordPress plugin “advanced view framework” id like to make an ACF custom field as a shortcode and display it on a post , the custom field will contain a shortcode . but now it only diplays the shotcode as the actual shortcode – how do i fix this?”
Answer:In WordPress, you can nest shortcodes and process them so that the inner shortcode is rendered correctly. The issue you’re experiencing happens because WordPress does not automatically process shortcodes within the output of another shortcode.
To fix this in the Advanced View Framework or any custom WordPress plugin, you need to ensure that the output of the outer shortcode is passed through the
do_shortcode()
function. Here’s how you can address this:1. Modify Your Custom Shortcode CallbackIf you are creating a custom shortcode to display an ACF field, update the callback function to process the inner shortcodes. Here’s an example:
php
Copy code
add_shortcode('acf_field_shortcode', function ($atts) { $atts = shortcode_atts([ 'field' => '', 'post_id' => null, ], $atts); // Get the ACF field value $field_value = get_field($atts['field'], $atts['post_id']); // Process shortcodes within the field value return do_shortcode($field_value); });
With this setup:
[acf_field_shortcode field="your_field_name"]
?will render the ACF field’s value, processing any shortcodes inside it.
- You must be logged in to reply to this topic.