WordPress.org

Ready to get started?Download WordPress

Forums

Types - Custom Fields and Custom Post Types Management
[resolved] WYSIWYG auto p? (6 posts)

  1. Eccola
    Member
    Posted 2 years ago #

    Hello,
    when using WYSIWYG custom field, it outputs text raw, without <p> -paragraphs. This is very bad for my clients, who don't know HTML. I'm using <?php echo get_post_meta($post->ID, 'wpcf-wysiwygfield', true);?> in my templates. Is there a way to activate the 'auto p'? Otherwise, everything works nice, thank you.

    http://wordpress.org/extend/plugins/types/

  2. helgatheviking
    Member
    Posted 2 years ago #

    you have to apply the autop and probably the other filters that are normally applied to the_content() to the data you retrieve from get_post_meta.

    this is why i usually do in similar situations:

    /* @Recreate the default filters on the_content
    -------------------------------------------------------------- */
    add_filter( 'meta_content', 'wptexturize'        );
    add_filter( 'meta_content', 'convert_smilies'    );
    add_filter( 'meta_content', 'convert_chars'      );
    add_filter( 'meta_content', 'wpautop'            );
    add_filter( 'meta_content', 'shortcode_unautop'  );
    add_filter( 'meta_content', 'prepend_attachment' );

    then change your code to:

    <?php $text = get_post_meta($post->ID, 'wpcf-wysiwygfield', true); ?>
    <?php echo apply_filters('meta_content',$text); ?>
    ?>
  3. helgatheviking
    Member
    Posted 2 years ago #

    edited: nm.

  4. Eccola
    Member
    Posted 2 years ago #

    Thanks for the tips helgatheviking! I will try this, and certainly will read the plugin documentation this time.

  5. helgatheviking
    Member
    Posted 2 years ago #

    sure thing. it probably isn't in the plugin docu. it is a trick i learned when doing metaboxes with WP Alchemy. remember that WP does not save the paragraph tags in the database. it automatically applies them with the wpautop filter based on line breaks. so any time you want to your front end code to match what you see in the_editor you must run it through that filter.

  6. smelly586
    Member
    Posted 2 years ago #

    thx helgatheviking, really saved my day with this solution :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic