Skip to content

Tag: html

How to disable wordpress html filter for posts and pages?

In some versions of WordPress there is a filter that strips some tags from the html code. If you want to remove this filter just open wp-includes/kses.php and find this row:

function kses_init_filters() {
    // Normal filtering.
    add_filter('pre_comment_content', 'wp_filter_kses');
    add_filter('title_save_pre', 'wp_filter_kses');

    // Post filtering
    add_filter('content_save_pre', 'wp_filter_post_kses');
    add_filter('excerpt_save_pre', 'wp_filter_post_kses');
    add_filter('content_filtered_save_pre', 'wp_filter_post_kses');
}

and comment out the rows that you need:

function kses_init_filters() {
    // Normal filtering.
    add_filter('pre_comment_content', 'wp_filter_kses');
    add_filter('title_save_pre', 'wp_filter_kses');

    // Post filtering
    //add_filter('content_save_pre', 'wp_filter_post_kses');
    add_filter('excerpt_save_pre', 'wp_filter_post_kses');
    //add_filter('content_filtered_save_pre', 'wp_filter_post_kses');
}

Then if you save the post in html it’s OK, but if you switch to normal view and then go back to html view the tags could be stripped again. This hapens most likely from the MCE Editor and to resolve this issue you could install a plugin called TinyMCE Valid Elements or some similar plugin.

How to add a 1px border to a table with CSS?

Problem

I want to have a one-pixel one-color solid border around a table and its cells. Adding border="1" to the table tag isn’t suitable, because it looks horrific in most of the browsers.

Solution with HTML only

Back in the old days we used to use just HTML to create a one-pixel border. Some people even used 1×1 pixel transparent gifs, but let’s not go into that. The easiest way to achieve the border was to use nested tables: outer table that provides the border color and inner table that holds the content.

Here’s an example:

Cell 1 Cell 2
Cell 3 Cell 4

Looks pretty fine, doesn’t it? However, let’s look into the code:

How to allow more html tags in the wordpress comments?

Scenario: I am using the tinymcecomments plugin to give some formatting capabilities to commenters. Also oEmbed for Comments is nice one – when you put a link to youtube or vimeo it automatically embeds the video.
With the latest WP update I realised the span tag was removed from comments; colors attributes are filtered by the kses filter.