Hello,
I have created a few shortcodes for a current project. In the default WordPress editor they work fine. When used in a rich_text field through carbon fields they are not being parsed correctly, just echoing out “[shortcode-name]” on the page. Please let me know if this is in the queue to be fixed.
Thank you
-Jon
Parsing shortcodes is not something that should happen when saving the field's value, rather you need to do this when outputting the text stored by the field.
You would need to pass the string from the meta through do_shortcode() in order for this to be converted to the output markup.
There are other functions that WordPress applies to a post/page's main content when the_content() is called. Those are all assigned to the the_content filter, so one way to go would be: echo apply_filters('the_content', $meta_string).
Keep in mind that if you have some plugin (such as one to add social links to the end of a blogpost's content) that adds more functions to this filter you may get some unwanted content.
Here's a list of the default functions that WordPress applies to the_content filter:
wptexturizeconvert_smiliesconvert_charsdo_shortcodewpautopshortcode_unautopprepend_attachment@georgeHtmlBurger thank you for the fast response. That solved it & makes much more sense now.
For others wandering how to implement:
function carbon_parse_shortcodes($meta_string){
return apply_filters('the_content', $meta_string);
}
<?php echo carbon_parse_shortcodes($layout['column1']); ?>
We're glad this works for you.
Most helpful comment
@georgeHtmlBurger thank you for the fast response. That solved it & makes much more sense now.
For others wandering how to implement:
function carbon_parse_shortcodes($meta_string){ return apply_filters('the_content', $meta_string); }<?php echo carbon_parse_shortcodes($layout['column1']); ?>