7

I would like to provide our WP users (authors) with a tinyMCE editor instead of standard textarea for their "Biographical Info" on the Profile page.

I have spent a lot of time searching online for plugins and references for how to accomplish this without a satisfying solution.

Any tips would be appreciated.

4 Answers 4

4

I found a very helpful blog post which shows exactly how to accomplish what I am after with only three small changes to the user-edit.php page.

First Change

I had to add a class name to the <textarea> tag for the description.

<textarea name="description" id="description" rows="5" cols="30"
  class="CLASS_NAME_HERE"><?php echo esc_html($profileuser->description); ?>
</textarea><br />

Second Change

I had to add a function call to wp_tiny_mce() like so.

<?php wp_tiny_mce( false, array( "editor_selector" => "CLASS_NAME_HERE" )); ?>

Note, the first argument of wp_tiny_mce (if true) will display the really stripped down version of the editor (like you'd see on the Quick Post).

Third Change

By default, Wordpress will strip out certain tags (those defined in $allowedtags) from the user description field. So, I found a plugin which basically removes the html restrictions. The plugin is called Weasel's Html Bios.

3
  • 1
    TIP: You can echo when using the esc functions, just append the name with _e, eg. esc_html_e( $data ), esc_url_e( $url ) etc..
    – t31os
    Commented Dec 8, 2010 at 10:09
  • In the future please wait at least a day before answering your own question. When questions are asked-and-answered it discourages others from participating and offering ideas. That said, please mark your answer as the answer as soon as you can.
    – EAMann
    Commented Dec 8, 2010 at 16:39
  • You should never modify WP core files. You may think that your unique problem can only be accomplished by hacking the core, but trust me, 99.9999% of the time, there's a way to do it without touching the core. If you're looking at this answer and thinking of implementing it, PLEASE do yourself a favor and look at the other answers that approach this correctly.
    – butlerblog
    Commented Oct 5, 2018 at 19:44
4

The above answer works, however it breaks every time WordPress is updated, isn't portable, and modifies core WordPress files (a huge no no).

It can be done entirely within hooks and filters in functions.php or a theme, or in a plugin. See here:

https://wordpress.stackexchange.com/a/33575/736

3

We should add js lib and init editor for id="description"

function mysite_show_extra_profile_fields($user) {
    wp_enqueue_editor();

    ?>
    <script>
    document.addEventListener("DOMContentLoaded", function(event) {
        var id = 'description';
    
        wp.editor.initialize(id, {
            tinymce: {
                wpautop: true
            },
            quicktags: true
        });
    });
    </script>
    <?
    }
    
add_action('show_user_profile', 'mysite_show_extra_profile_fields');
1

As Tom mentions above It’s probably best not to edit the WordPress core files, those will get wiped out when you update to the latest version.

I’ve written a plugin that replaces the Biographical Info profile field with the WordPress visual editor, TinyMCE, allowing you to editor an author’s biography using rich text using a new function, wp_editor(), that was released with WordPress 3.3.

http://wordpress.org/extend/plugins/visual-biography-editor/

Using this plugin will ensure that the editor isn’t wiped out with the next core update, which you should definitely do for security reasons.

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.