Custom Fields
Re-Envisioned
Support General WYSWIYG field and Shortcodes

  • Creator
    Topic
  • #10652
    Resolved tsquez
    Participant

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

    https://metabox.io/support/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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Author
    Replies
  • #10655
    tsquez
    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 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
    tsquez
    Participant

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

    #10680
    Anh Tran
    Keymaster

    Yes, that’s right!

    #13972
    yumikom
    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 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 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.