Forums

TinyMCE Format Options, remove h1, h2, pre (11 posts)

  1. Stompit
    Member
    Posted 4 months ago #

    Hi There,
    Have searched high and low for a solution to this, but the information available on the wordpress WYSIWYG is very fragmented.

    I have developed a couple of Wordpress based sites for clients and of course the h1 and h2 tags have been reserved in the page templates and thus I would not like them to be available in the TinyMCE editor.

    Basically I'd like to remove the address, pre, h1 and h2 options from the "Formatting" drop-down.

    Soooo, how the hell to you do it!?

    Thanks Folks
    D

  2. Stompit
    Member
    Posted 4 months ago #

    Any takers?

  3. Stompit
    Member
    Posted 4 months ago #

    Pretty please?

  4. Stompit
    Member
    Posted 4 months ago #

    Ahh come on, I've seen a few people with the same problem and no solution, someone must know this? :)

  5. LindyNorris
    Member
    Posted 3 months ago #

    I want to know the answer to this one as well. Stompit if you figure it out, will you please share. Thanks!
    ~Lindy

  6. mleuffer
    Member
    Posted 3 months ago #

    Hi,
    I found the solution.
    I was looking for the same clean-client-ready solution
    so I arrived here with my question and had to search a little more by myself...
    I managed to have just the p, h3 and h4 in my menu.
    so. kind of explaining the way I found it:
    tinyMCE usually store settings in theme/advanced/editor_template.js inside its folder (wp-includes/js/tinymce/) but after editing the correct line, nothing changed... so I looked in its root folder (same as above) and found the wp-tinymce.php with this code :

    if ( isset($_GET['c']) && 1 == $_GET['c'] && false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') && ( $file = get_file($basepath . '/wp-tinymce.js.gz') ) ) {
    	header('Content-Encoding: gzip');
    	echo $file;
    } else {
    	echo get_file($basepath . '/wp-tinymce.js');
    }
    exit;

    It means it will look inside the .gz file if your server support unzipping or in the /wp-tinymce.js file if not.
    So you can replace the code above by this:

    echo get_file($basepath . '/wp-tinymce.js');
    exit;

    and edit the wp-tinymce.js like this :
    - search for "theme_advanced_blockformats" in the file.
    - the first occurrence will be :
    ... theme_advanced_blockformats:"p,address,pre,h1,h2,h3,h4,h5,h6", ...
    - remove the unwanted tags :
    ... theme_advanced_blockformats:"p,h3,h4", ...
    IT WORKS !
    Now you could also let the .php file unmodified and after saving the wp-tinymce.js, use a gzip utility to gzip it and you'd replace the wp-tinymce.js.gz this way. That's what I did.
    Enjoy Wordpress ;)
    Mik*

  7. willshouse
    Member
    Posted 2 months ago #

    there should be a way to write a plugin which modifies the "theme_advanced_blockformats" variable. by using a plugin with a hook / loop setup, you wouldn't have to change any of the wordpress core files and thus would be OK for use with upgraded and future versions.

    Also, I believe that the code above is allowing wordpress to use the compressed version of tinymce which should load faster (see: http://wiki.moxiecode.com/index.php/TinyMCE:Compressor/PHP)

    by changing that code you are forcing the editor to load as the uncompressed version.

    changing the block formats is something I'd like to do as well, but I want to do it the "right" way. i'll post the solution here when I find it, but it may be a while as this isn't at the top of my priorities right now :)

  8. guasi
    Member
    Posted 2 weeks ago #

    Here is the code to create your own plugin to edit the 'theme_advanced_blockformats' string. It works for me using 2.8.5

    function customformatTinyMCE($init) {
    	// Add block format elements you want to show in dropdown
    	$init['theme_advanced_blockformats'] = 'p,h3,h4,h5,h6';
    
    	// Add elements not included in standard tinyMCE doropdown p,h1,h2,h3,h4,h5,h6
    	//$init['extended_valid_elements'] = 'code[*]';
    
    	return $init;
    }
    
    // Modify Tiny_MCE init
    add_filter('tiny_mce_before_init', 'customformatTinyMCE' );
  9. glogurl
    Member
    Posted 1 week ago #

    I did all of the below:

    if ( isset($_GET['c']) && 1 == $_GET['c'] && false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') && ( $file = get_file($basepath . '/wp-tinymce.js.gz') ) ) {
    header('Content-Encoding: gzip');
    echo $file;
    } else {
    echo get_file($basepath . '/wp-tinymce.js');
    }
    exit;

    It means it will look inside the .gz file if your server support unzipping or in the /wp-tinymce.js file if not.
    So you can replace the code above by this:

    echo get_file($basepath . '/wp-tinymce.js');
    exit;

    and edit the wp-tinymce.js like this :
    - search for "theme_advanced_blockformats" in the file.
    - the first occurrence will be :
    ... theme_advanced_blockformats:"p,address,pre,h1,h2,h3,h4,h5,h6", ...
    - remove the unwanted tags :
    ... theme_advanced_blockformats:"p,h3,h4", ...

    and it still has not removed my other formatting options I only want p,h1. Any help would be great.

  10. glogurl
    Member
    Posted 1 week ago #

    i got it!

  11. Stompit
    Member
    Posted 1 week ago #

    Superb, thanks folks! :)

Reply

You must log in to post.

About this Topic