0

I'm using 2 extra TinyMCE editors on my pages to add extra textfiels in my theme pages. I now realize that the auto-embed feature is not supported on content delivered thought custom fields. So i need to tell WordPress to enable this on these two extra custom fields.

Here is an example of the back-end part included in my functions.php file:

    function monster_meta_options() {
    global $post;
    $custom = get_post_custom($post->ID);
    $monster_tiny_1 = (isset($custom['monster_tiny_1'][0]) ? $custom['monster_tiny_1'][0] : '');
    //Use nonce for verification
    wp_nonce_field( plugin_basename( __FILE__ ), 'myplugin_noncename' );

    //TinyMCE field! :)
    $args = array('wpautop' => true, 'media_buttons' => true, 'quicktags' => true,'textarea_name' => 'monster_tiny_1');
    wp_editor( html_entity_decode($monster_tiny_1), 'lower-left', $args);   
}

This is an example of how i output my custom field on the front end. A custom page named om-monster.php

                        <div class="entry-content-left">
                        <?php 
                            $custom_field = get_post_meta($post->ID, 'monster_tiny_1', true);
                            $monster_tiny_1 = (isset($custom_field) ? $custom_field : '');

                        if ($monster_tiny_1 != '') {

                            echo wpautop(html_entity_decode($monster_tiny_1));

                        } ?>
                    </div><!-- .entry-content-left -->

So how can i enable autoembed on the content written in the custom TinyMCE editor (should be the same as a normal text field).

3

You're probably best off using echo apply_filters( 'the_content', html_entity_decode( $monster_tiny_1 ) ); instead of echo wpautop(html_entity_decode($monster_tiny_1)); and similar, which will run the autoembed behavior.

  • Just tried it out myself, and Thank you! this works perfectly! – Ole Henrik Skogstrøm Mar 21 '12 at 18:31
  • however i needed to add the code html_entity_decode to the variable because i use esc_attr when i put the information into the database. This is my working code 'echo apply_filters( 'the_content', html_entity_decode($monster_tiny_1) );' – Ole Henrik Skogstrøm Mar 21 '12 at 18:33
  • 1
    esc_attr() is really meant as escaping for display in an HTML attribute. You should use something like wp_kses_post() for sanitizing before saving to the database. – helenhousandi Mar 22 '12 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.