Use quicktags toolbar on any textarea

I have stumbled into this very same issue, and got the quicktags to work.

Here’s the code to add to functions.php:

<?php
add_action('admin_print_footer_scripts','my_admin_print_footer_scripts');
function my_admin_print_footer_scripts()
{
?>
<script type="text/javascript">/* <![CDATA[ */

    var id = "myID"; // this is your metabox's textarea id

    settings = {
        id : id,
        buttons: 'strong,em,link' 
    }

    quicktags(settings);

/* ]]> */</script>
<?php } ?>

This is the basic code that should get quicktags to work.

In case you want to go through all the (Verve) Metaboxes, and assign a toolbar, the following code could do the trick:

add_action('admin_print_footer_scripts','my_admin_print_footer_scripts');
function my_admin_print_footer_scripts()
{
    ?><script type="text/javascript">/* <![CDATA[ */
    jQuery(function($)
    {
        var i = 1;
        $('.verve_meta_box_content textarea').each(function(e)
    {
        var id = $(this).attr('id');
            if (!id)
    {
        id = 'customEditor-' + i++;
        $(this).attr('id',id);
        }

            settings = {
                id : id,
                buttons: 'strong,em,link' // Comma separated list of the names of the default buttons to show. Optional.
            }

            quicktags(settings);
         });

  });
/* ]]> */</script>
<?php } ?>

Also, in order to keep the line breaks on your front end, make sure you use “the_content” filter when outputting the textarea content, as so:

// schedule is the slug of the custom meta field
$schedule_juice = get_post_meta($current_post_ID, "schedule", false);
// preserve line breaks     
$content = apply_filters('the_content', $schedule_juice[0]);
echo $content; 

The priority with which the my_admin_print_footer_scripts method was being called was the blocking issue.

Good luck!

Leave a Comment