Cmb2: Shortcodes don't work in a wysiwyg field

Created on 15 Apr 2015  路  9Comments  路  Source: CMB2/CMB2

Shortcodes don't work in a wysiwyg field but work in regular wordpress body field in pages. Any idea what might be causing this? I'm specifically using formidable forms, but I've also tried with other shortcodes.

Most helpful comment

Were you not filtering your meta data with the_content? That would probably be your better option:

$wysiwyg = apply_filters( 'the_content', get_post_meta( get_the_id(), $prefix . 'wysiwyg_meta_name', true ) );

Arbitrarily picked variable and meta data names. But something like that instead. Note that my example uses a $prefix variable, instead of how the wiki example does it.

All 9 comments

I had to wrap the outputted content with do_shortcode.

Were you not filtering your meta data with the_content? That would probably be your better option:

$wysiwyg = apply_filters( 'the_content', get_post_meta( get_the_id(), $prefix . 'wysiwyg_meta_name', true ) );

Arbitrarily picked variable and meta data names. But something like that instead. Note that my example uses a $prefix variable, instead of how the wiki example does it.

$joya_air_page_meta['writers_text'] = do_shortcode(get_post_meta ( $post->ID, '_jo_air_page_writers_text', true ));

Right, I gotcha. I'm just suggesting that you'll probably want to filter a wysiwyg field through the_content instead of using do_shortcode.

You'll still get your shortcodes resolved, but you'll also get all the normal defaults you'd expect from the standard TinyMCE (wysiwyg) editor.

Downside to using the the_content filter is that it's typically used to output things like social sharing icons, and other things that plugins add. Can be a pain.

The wiki actually has an example function for doing this type of thing: https://github.com/WebDevStudios/CMB2/wiki/Field-Types#wysiwyg

Good point, and excellent example snippet there!

I've done this using following code :

$wysiwyg = apply_filters( 'the_content', get_post_meta( get_the_id(), $prefix . 'wysiwyg_meta_name', true ) );

Thanks @yeahsmaggy , the code run well.

@jalberts got the best solution
Thank You!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

angelorocha picture angelorocha  路  6Comments

cehojac picture cehojac  路  3Comments

alanef picture alanef  路  4Comments

apokyro picture apokyro  路  5Comments

noquierouser picture noquierouser  路  8Comments