Support » Plugins » Custom fields with WYSIWYG

Viewing 6 replies - 1 through 6 (of 6 total)
  • I’m actually surprised that this doesn’t have proper support out of the box in WP yet. The more WP is used as a CMS the more this feature would be worthwhile. There are probably other ways to do this so if you have found one, please share it with us. Not sure if this will help you or not. You will need to do some hand coding.

    I have had some success using rc_custom_field gui from rhymed code

    With this plug in installed a couple of quick edits are required to a couple of the files.

    If you are using pages, edit rc-custom-field-gui.php and add:

    add_action( 'edit_page_form', array( 'rc_custom_field_gui', 'insert_gui' ) );

    after line 42.

    In rc-custom-field-gui.class.php find the secton that deals with text areas and add class=”mceEditor” to the textarea generating code around line 138 so that it reads:

    $out =
          '<tr style="padding-bottom:30px;">' .
          '<th scope="row" valign="top">' . $title . ' </th>' .
          '<td> <textarea id="' . $name . '" name="' . $name . '" type="textfield" rows="' .$rows. '" cols="' .$cols. '" class="mceEditor">' .attribute_escape($value). '</textarea></td>' .
          '</tr>' . '<tr><td colspan="2">&nbsp</td></tr>';
        return $out;

    With those two things set, go to wp-includes > js > tinymce > tiny_mce_config.php and around line 137 (tinyMce init settings) change the first two init. lines to read:

    'mode' => 'specific_textareas',
    'editor_selector'  => 'mceEditor',

    Make sure the plugin in activated and empty your cache. Refresh your edit posts/pages.

    Remember to re-edit the tinyMce config file if you change any core files when you upgrade to a new version of WP.

    Best of luck

    A

    Great tip here, Andy_woz – thank you! 🙂

    I haven’t tested it out myself, but I agree that with WordPress being used more and more as a CMS, it’s necessary to have some WYSIWYG for custom fields.

    I guess I should have mentioned that you will need to add the functionality in your templates to pull the content of the custom fields. However that’s more to do with the plug in itself than the thread which is about getting a wysiwyg editor to appear for the custom field. See the rymed code site and plug in instructions for the best way to get your custom field content into your templates.

    A

    Just a note that as of 2.7 this no longer works. The $initArray in tiny_mce_config.php is no longer used.

    A

    FYI as of v 2.7 the $initArray has moved to wp-admin/includes/post.php line 1237. The above modifications for $initArray remain the same.

    Obviously the down side to this as always is that we are modifying a core file that will get blitzed with every upgrade so keep the settings handy.

    Ok I’ve had some luck with this added to functions.php

    /**
     * Add Tiny MCE editor to textareas used by custom_field_gui
     */
    
    function change_mode_cf( $init ) {
        $edmode = 'specific_textareas';
    	$init['mode'] = $edmode;
        return $init;
    }
    add_filter('tiny_mce_before_init', 'change_mode_cf');
    
    function change_select_cf( $init2 ) {
        $edselect = 'mceEditor';
    	$init2['editor_selector'] = $edselect;
        return $init2;
    }
    add_filter('tiny_mce_before_init', 'change_select_cf');

    If anyone knows how to squeeze both changes to the init array into one filter that would be fantastic.

    The bonus here is that the changes are now part of your theme and you don’t have to worry about core files anymore.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom fields with WYSIWYG’ is closed to new replies.