Forums

add_editor_style for plugin (3 posts)

  1. dwieeb
    Member
    Posted 1 year ago #

    I'm using add_editor_style() for my theme that I made. However, while attempting to make a plugin, I noticed that add_editor_style()'s parameter is a path relative to the theme's root. What if I have a CSS file I need to include in TinyMCE but it's located in my plugin directory? Wouldn't it make more sense for add_editor_style() to accept a path from root or url? Anyone competent enough to make a theme or plugin is competent enough to pass get_bloginfo('url') or get_bloginfo('template_directory') or get_bloginfo('stylesheet_directory') along with the path to the css file in add_editor_style().

  2. Mark / t31os
    Moderator
    Posted 1 year ago #

    add_editor_style() is only a convenience function to adjust the css parameters passed along to the TinyMCE configuration.

    You can however hook onto tinymce_before_init and adjust the TinyMCE config .. OR .. if you're creating your own instance with wp_tiny_mce(), the second arg accepts an array of configuration settings to pass along to TinyMCE instance..

    document_base_url can be used to set an alternate base directory to use with the TinyMCE instance..

    Info on possible configuration options.
    http://wiki.moxiecode.com/index.php/TinyMCE:Configuration

    Hope that helps..

  3. Frank Bültge
    Member
    Posted 6 months ago #

    an example for an solution:

    add_filter( 'mce_css', 'filter_mce_css' );
    
    	public function filter_mce_css( $mce_css ) {
    		global $current_screen;
    
    		if ( 'issue' === $current_screen -> post_type )
    			$mce_css .= ', ' . plugins_url( 'css/editor-style-' . $current_screen -> post_type . '.css', __FILE__ );
    
    		return $mce_css;
    	}

Topic Closed

This topic has been closed to new replies.

About this Topic