## Display Custom Field Value Via Shortcode Inside Excerpt

Question

I have the following function:

function dessert_function( $atts ) {$atts = shortcode_atts( array(
'post_id' => get_queried_object_id(),
), $atts, 'dessert' ); return dessert_meta($atts['post_id'], 'dessert', true );
}

add_shortcode('dessert', 'dessert_function');


It allows to store a value inside a custom field 'dessert' and display that value using a shortcode [dessert] inside a post.

So if for a custom field dessert the value is cake.

I would like to be able to include a shortcode [dessert] inside an excerpt and for it to display cake.

At the moment when I save the article instead a shortcode it displays blank.

I am assuming it needs a filter.

I found a few solutions but none work.

For example:

add_filter('get_the_excerpt', 'do_shortcode');


0
1 year 2021-03-30T15:59:20-05:00 0 Answers 0 views 0