Remove tags from the kses filter

The allowed tags are stored in $allowedposttags (located in /wp-includes/kses.php) as an array. For each element it looks something like this: $allowedposttags = array( ‘div’ => array( ‘align’ => true, ‘dir’ => true, ‘lang’ => true, ‘xml:lang’ => true, ) ); You can remove a single element of an array via unset unset($allowedposttags[‘div’]);

Remove all table widths from editor content

I would approach this by modifying the attributes allowed in the table, tr, and td markup from wp_kses. wp_kses is a function that runs on the content to filter out unwanted tags and attributes. It stands for KSES Strips Evil Scripts, but it does much more than that. It’s a large and sometimes convoluted function, … Read more

WP Editor strips input placeholder attribute

The list of allowed elements and attributes is stored in the global variable $allowedposttags which is set in wp-includes/kses.php. To override it create a simple mu plugin with the following content: <?php # -*- coding: utf-8 -*- /** * Plugin Name: Enable placeholder attribute for input elements in post tags. * Version: 2012.07.18 */ add_action( … Read more

How to allow data:image attribute in src tag during post insert?

Thanks to naththedeveloper from StackOverflow. His answer worked for me. Well, this was a nightmare to find, but I think I’ve resolved it after digging through the WordPress code which hooks in through wp_insert_post. Please add this to your functions.php file and check it works: add_filter(‘kses_allowed_protocols’, function ($protocols) { $protocols[] = ‘data’; return $protocols; }); … Read more

What is the difference between strip_tags and wp_filter_nohtml_kses?

Technical difference is kinda obvious. PHP one is single function, using logic in PHP code. WP one is one of family of functions, based on third party KSES library. Is there practical difference between these two specific functions? I think the important point is that strip_tags() was made for utility, while KSES was made for … Read more

Allowing more elements in comments via functions.php

Here is an example how to allow a commenter to insert HTML5 video into the comment. Both <video> and <source> elements has two allowed attributes. preprocess_comment filter is applied when saving the comment to the DB. See /wp-includes/kses.php for $allowedtags array structure. function myAllowHtmlComments($comment) { global $allowedtags; $allowedtags[‘video’] = array( ‘width’ => true, ‘height’ => … Read more