4

What's the simplest way to add a second HTML editor to the post/page admin and show the content in a template?

What I need is something like a custom field that supports html, but I don't need the options to name the field. And I don't need a visual editor like tinyMCE; just html will do.

What I'm thinking of is simply a small text-editor box that sits under the main visual/html editor and shows the resulting html in a template via <?php if ( function_exists('my_extra_editor_content') ) ... with the text/html in a styleable div.

Plugins like http://wordpress.org/extend/plugins/custom-field-template/ and http://wordpress.org/extend/plugins/developers-custom-fields/ offer too much in terms of functions and choices.

5 Answers 5

3

I use Bill Erickson's custom meta boxes or plugin like Secondary HTML Content (probably the easiest solution)

1
  • Thanks, I tried both and both work well for different needs; Custom Meta Boxes and Fields for complex uses, and the Secodnary HTML Content for simple sites. But I now use CMB&F for everything. Commented Jul 16, 2014 at 16:15
2

I dont know if this will help but any Custom Field input will support html. I use html there all the time for headings and custom text in posts and pages.

1

For future travelers, the custom metaboxes are not a good idea for adding a second editor in pages. You should use wp_editor function inside the edit_page_form action so the form can be displayed. (You should use edit_form_advanced action for custom post types)

Then you can use the save_post and get the value of the editor from $_POST object. Here's an example:

add_action( 'edit_page_form', 'se24801_add_second_editor' );
function se24801_add_second_editor() {
    echo '<h2>Second Content </h2>'; 
    $content = get_post_meta( $post->ID, 'second_content', true );
    wp_editor(
        $content,
        'second_content',
        array(
            'media_buttons' =>  true,
        )
    );    
} 

add_action( 'save_post', 'se24801_save_second_content' );
function se24801_save_second_content( $post_id ) {
    if(isset( $_POST['second_content'] ) ) {
        update_post_meta( $post_id, 'second_content', $_POST['second_content'] );
    }  
}
0

Have you tried a textarea in a meta box? Meta boxes are more user friendly.

About your requirement, it sounds like just a textarea will do. Please be aware that even full tinyMce based editors are possible using existing WordPress libraries.

-2

Update from 2020. This is now extremely easily achievable with the Advanced Custom Fields plugin and using its provided function call the_field('field_ref') to insert in the page.

1
  • I point out in my original question that plugins offer too much functionality. Commented Jun 13, 2020 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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