WYSWIYG field and Shortcodes

Support General WYSWIYG field and ShortcodesResolved

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #10652
    tsqueztsquez
    Participant

    Does the WYSWIYG field allow shortcodes? I saw this post:

    https://support.metabox.io/topic/shortcode-in-wysiwyg-type/

    but I think I am having a hard time understanding. Just for testing purposes I used the sample code from the WYSWIYG documentation https://docs.metabox.io/fields/wysiwyg/:

    array(
        'name'    => 'WYSIWYG / Rich Text Editor',
        'id'      => 'field_id',
        'type'    => 'wysiwyg',
        'raw'     => false,
        'options' => array(
            'textarea_rows' => 4,
            'teeny'         => true,
        ),
    ),
    

    So how exactly would I use shortcodes with this?

    Thank for all you do and for all the help. It's greatly appreciated.

    #10655
    tsqueztsquez
    Participant

    OK sorry I just read towards the end of the WYSWIYG documentation:

    Note that the helper function doesn’t format the value of this field nor run shortcodes in the content.

    I do have three shortcodes that I created to be run in this area: one to show the title, one to show the date and one to show the author.

    How would I add those three shortcodes to this:

    $value = rwmb_meta( $field_id );
    echo do_shortcode( wpautop( $value ) );
    

    Thanks in advance.

    #10658
    Anh TranAnh Tran
    Keymaster

    Hi Thomas,

    The final code in your previous post parses and runs the shortcodes. Just put the shortcodes in the field's content and they will render well.

    Or am I missing anything?

    #10670
    tsqueztsquez
    Participant

    So all I do is just make sure to add the do_shortcode and it will run any shortcode added there?

    #10680
    Anh TranAnh Tran
    Keymaster

    Yes, that's right!

    #13972
    yumikomyumikom
    Participant

    Hi Anh,

    Is there filter which execute 'do_shortcode' for all metabox?
    For example like filters for widgets.
    add_filter('widget_text', 'do_shortcode' );

    Best regards.

    #13975
    Anh TranAnh Tran
    Keymaster

    Hi yumikom, please try the rwmb_the_value filter:

    add_filter( 'rwmb_get_value', function( $value, $field, $args, $object_id ) {
        if ( 'wysiwyg' === $field['type'] ) {
            $value = do_shortcode( $value );
        }
        return $value;
    }, 10, 4 );
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.