Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

reading the quicktags.dev.js i see in the comments

 * Run quicktags(settings) to initialize it, where settings is an object containing up to 3 properties:
 * settings = {
 *   id : 'my_id',          the HTML ID of the textarea, required
 *   buttons: ''            Comma separated list of the names of the default buttons to show. Optional.
 *                          Current list of default button names: 'strong,em,link,block,del,ins,img,ul,ol,li,code,more,spell,close';
 * }
 *
 * The settings can also be a string quicktags_id.
 *
 * quicktags_id string The ID of the textarea that will be the editor canvas
 * buttons string Comma separated list of the default buttons names that will be shown in that instance.

which seems like i should be able to call the javascript functions quicktags(), pass it at least the ID of a text area and I should get the quicktags editor created just before any textarea. (i'm working in a metabox).

however, if i put the following in my code:

try { quicktags( '_repeating_textareas_meta[repeating_textareas][0][textarea]'); } catch(e){}

which I essentially copied from bit of javascript that WP has it in the source and added my metabox's ID.

it prints out the div where the quicktags toolbar should be but doesn't make any buttons

<div id="qt__repeating_textareas_meta[repeating_textareas][0][textarea]_toolbar" class="quicktags-toolbar"></div> 

console.log doesn't show any errors. and i swear that this time i have undone all potential tampering to source code.

EDIT:

i've isolated the problem down to where the script appears in the source... using Fred Rocha's function works great (and much like i anticipated) if it runs on the admin_print_footer_scripts but not on after_wp_tiny_mce... it results in the same empty toolbar i was getting.

other parts of my jquery plugin need to run after the tinymce settings are initialized (since i'm straight borrowing the existing settings), so why would it work properly on the one hook but not on a later hook?

share|improve this question
    
console.log doesn't show any errors – of course, your catch statement prevents that. :) –  toscho Mar 9 '12 at 5:50
    
even trying to console.log(e) inside the catch statement i don't get an error, b/c the catch statement isn't run.... since an empty toolbar is being generated. –  helgatheviking Mar 9 '12 at 13:46
    
What happens if you fill the buttons parameter? –  toscho Mar 9 '12 at 21:51
1  
nothing. i've tried that too. –  helgatheviking Mar 9 '12 at 23:36
    
@toscho any idea why Fred Rocha's answer would work on the admin_print_footer_scripts hook but not on the after_wp_tiny_mce hook? –  helgatheviking Mar 27 '12 at 18:25
show 2 more comments

2 Answers

up vote 3 down vote accepted

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!

share|improve this answer
    
care to share any of that jquery 'magic'? b/c i'm trying to add it any repeating textareas in a metabox. so i am dynamically generating the ID for the textarea. works fine w/ tinyMCE (go fig) but i still get the empty toolbar here. the script is running about dead last, so quicktags have been loaded. this does work if i have a statically named ID. –  helgatheviking Mar 26 '12 at 23:56
    
Updated answer! –  Fred Rocha Mar 27 '12 at 11:01
    
i disabled all of my own scripts and added your code and finally some success!! now i need to figure out what i have written that is conflicting. thanks! also- instead of using the_content filter i usually create a meta_content filter. then i add the functions that are typically added to the_content to meta_content... sort of a duplicate. i did this b/c plugins add things to the_content and so i got share buttons all over the screen one time! –  helgatheviking Mar 27 '12 at 17:13
    
You're welcome! Great to know i could be of assistance. Your custom based filter sounds good, WP is a wonderful, tailorable machine! –  Fred Rocha Mar 27 '12 at 17:44
add comment

I have been able to display Alex King's quicktag script in my comment form.

I have documented the steps and code here.

add_filter( 'comment_form_defaults', 'pc_comment_form_args' );

function pc_comment_form_args( $args ) { 
$args['comment_field'] = '<p class="comment-form-comment">' .
                         '<label for="comment">Comment</label>' .
                         '<script type="text/javascript">edToolbar("comment");</script>' .
                         '<textarea id="comment" name="comment" cols="45" rows="8" aria-required="true">' .
                         '</textarea>' .
                         '</p>';
 return $args;
 }

Just Download and enqueue the Alex Kings QuickTag Script. :-)

share|improve this answer
    
Then please inlcude (parts of) the document here. Else this answer does not provide any help. –  t f Nov 8 '13 at 7:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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