split content around a shortcode in a custom wp_editor

so here goes.

I am developing a custom content manager for WordPress. with this I have created a Block Manager, you add a block, you pick container size, background colour and so on.

One of the blocks is a 2 column content editor each side having a unique wp_editor.

The editor works fine however I am struggling with adding shortcodes within the editor.

Please bear in mind that the editor data is stored as part of a multidemensional array as I have shown below:

<?php
// Example content field
$blocks = $post->post_blocks;
$right_content = $blocks[‘content’][1][‘right’];
?>

The first thing I tried was adding shortcode support to the column content with:

<?php
add_filter( ‘custom_field’, ‘do_shortcode’ );
$custom_field_output = apply_filters( ‘custom_field’,
$custom_field_output );
echo ‘<div class=”custom-field”>’ . wpautop(
$custom_field_output ) . ‘</div>’;
?>

I then though about exploding the string from the array so that I could split before and after the shortcode then capture the shortcode itself and put it through the do_shortcode.

My questions are:

A – If I could get both options to work which would be the recommended approach?
B – Which one would give me the better flexibilty for customising the output?

And finally, sorry its a bit of a long one.

After attempting the first option I couldn’t get the desired result in fact the shortcode just stayed in text form. Can anyone see an error in the code?

For the second approach I would like some pointers, I would prefer not to be given the complete answer after all I would like to learn by doing.

Thank you all for your time.

Read more here:: split content around a shortcode in a custom wp_editor

Leave a Reply

Your email address will not be published. Required fields are marked *