0

I've been stuck in a simple issue for the last couple of hours:

I'm developing a website in which I use several wp_editor instances, all with custom buttons and styles. This is very simple to achieve by just adding the arguments directly to the wp_editor, in my custom posts.

My issue resides in trying to add custom buttons to ONLY the editor used for the standard regular Wordpress posts. This is because I did not create the instance manually, and I assume I have to use a filter function.

Here is how I'm adding the arguments in my wp_editor instances in my custom posts:

<?php
wp_editor(
    $options['news_title'],
    'news_title',
    array(
        'textarea_name' => 'page_options_home_page[news_title]',
        'media_buttons' => false,
        'textarea_rows' => 1,
        'tabindex' => 4,
        'quicktags' => false,
        'tinymce' => array(
            'toolbar1'=> 'bold,italic',
            'toolbar2'=> '',
            'toolbar3'=> '',
            //'content_css' => get_template_directory_uri() . "/build/styles/tiny-mce/page-options-mce-editor.css"
        ),
    )
);
?>

Here is how I would add a GLOBAL style to the wp_editor - also very simple, BUT this approach does not work for me as it affects all my other instances.

function my_format_TinyMCE( $in ) {
    //styles for the editor to provide better visual representation.
    $in['content_css'] = get_template_directory_uri() . "/build/styles/tiny-mce-editor.css";
    $in['block_formats'] = "Paragraph=p; Heading 1=h1; Heading 2=h2";
    $in['toolbar1'] = 'formatselect,bold,italic,underline,superscript,bullist,numlist,alignleft,aligncenter,alignright,link,unlink,spellchecker';
    $in['toolbar2'] = '';
    $in['toolbar3'] = '';
    $in['toolbar4'] = '';
    return $in;
}
add_filter( 'tiny_mce_before_init', 'my_format_TinyMCE' );

So...I'm trying to find some direction on how to target that specific wp_editor. In general, I'm having trouble passing arguments to specific wp_editor that I did not manually create (regular post editor, bbpress,etc). I want to remove a few button instances of those editors and keep them in my custom ones.

Any advice?

Thanks!

0

What you can do is use the get_current_screen() function to get what screen the current user is on ( in the admin panel ) and only add those global values whenever the user is viewing the post page:

function my_format_TinyMCE( $in ) {
    $screen = get_current_screen();

    if( is_object( $screen ) && 'post' == $screen->post_type ) {
        //styles for the editor to provide better visual representation.
        $in['content_css'] = get_template_directory_uri() . "/build/styles/tiny-mce-editor.css";
        $in['block_formats'] = "Paragraph=p; Heading 1=h1; Heading 2=h2";
        $in['toolbar1'] = 'formatselect,bold,italic,underline,superscript,bullist,numlist,alignleft,aligncenter,alignright,link,unlink,spellchecker';
        $in['toolbar2'] = '';
        $in['toolbar3'] = '';
        $in['toolbar4'] = '';
    }

    return $in;
}
add_filter( 'tiny_mce_before_init', 'my_format_TinyMCE' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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