• Resolved wnthne

    (@wnthne)


    How to stop Tinymce from stripping out HTML code
    I have a bordercolor in my table as shown below. Every time I shift from text to visual mode it is stripped out. How can I prevent this?

    <table align="left" bordercolor="#FFB36C" border="1" cellpadding="0" cellspacing="0">

    The same thing happens with &nbsp; or &160;
    How can I prevent HTML code from being stripped out?

    The odd thing is that after the editor strips out the non-breaking spaces, it seems to somehow “remember” they are there (does not remember the bordercolor, though), but if I copy and paste the code into a new file, of course they are not there and the formatting is messed up.

    So how can I prevent the editor from stripping out HTML code?

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Don’t switch from TEXT to VISUAL – it WILL do that – known quirk. Just use one or the other until you’ve saved the changes.

    You should apply a unique style to the table and then use CSS anyway.

    In HTML:

    <table class="tablex">your rows and columns here</table>

    in CSS:

    .tablex {
    //your styles here
    }

    Often you can use unique post or page id css also for such (depending on theme):

    #post-25 .entry-content table {
    //your styles here
    }

    If you want all tables in one style on the site just fix the table CSS…best done in a child theme or with a custom css plugin…

    You can also use a plug-in like Global Content Blocks or Post Snippets. These allow you to write small bits of code, and then create your own short code with them. WP will never strip out short code.

    Thread Starter wnthne

    (@wnthne)

    Thanks everyone for your responses – I appreciate it! The solution I ended with, I got from Josh Lobe, the Ulitimate TinyMCE developer. I pasted it into the main.php plugin file near the top and it seems to work 99% of the time. Of course, every time there is a new update in the plugin, I have to paste it in again.

    /**
    * Add to extended_valid_elements for TinyMCE
    *
    * @param $init assoc. array of TinyMCE options
    * @return $init the changed assoc. array
    */
    function my_change_mce_options( $init ) {
        // Command separated string of extended elements
        $ext = 'pre[id|name|class|style]';
    
        // Add to extended_valid_elements if it alreay exists
        if ( isset( $init['extended_valid_elements'] ) ) {
            $init['extended_valid_elements'] .= ',' . $ext;
        } else {
            $init['extended_valid_elements'] = $ext;
        }
    
        // Super important: return $init!
        return $init;
    }
    
    add_filter('tiny_mce_before_init', 'my_change_mce_options');
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How can I prevent HTML code from being stripped out?’ is closed to new replies.