I know that WordPress uses KSES to parse HTML and strip invalid XHTML so I took control of $allowedtags in my themes functions.php file inside a function then added ‘target’ keyed to an array which contains ‘_blank’ keyed to an empty array. I thought this would work but my link still seems to not contain the target attribute? I have tried re saving the HTML also.
Here is my code:
function add_required_html_tags()
{
global $allowedtags; //tap into wordpress global array of allowed tags
//$target
//$allowedtags[] = 'target';
$allowedtags['target'] = array('_blank'=>array()); //add target html tag in the style that wordpress expects
//var_dump($allowedtags);
}
add_action('init', 'add_required_html_tags', 10); //add action to initialise so we can access this tag everywhere.
and here is the result of a var_dump
array(15) { ["a"]=> array(2) { ["href"]=> bool(true) ["title"]=> bool(true) } ["abbr"]=> array(1) { ["title"]=> bool(true) } ["acronym"]=> array(1) { ["title"]=> bool(true) } ["b"]=> array(0) { } ["blockquote"]=> array(1) { ["cite"]=> bool(true) } ["cite"]=> array(0) { } ["code"]=> array(0) { } ["del"]=> array(1) { ["datetime"]=> bool(true) } ["em"]=> array(0) { } ["i"]=> array(0) { } ["q"]=> array(1) { ["cite"]=> bool(true) } ["s"]=> array(0) { } ["strike"]=> array(0) { } ["strong"]=> array(0) { } ["target"]=> array(1) { ["_blank"]=> array(0) { } } }
(the target element is at the end)
Can anyone see where I am going wrong?
I also tried changing _blank to a bool with the value of true. – no luck there.
Using wordpress 4.4.2
UPDATE:
code is now:
function add_required_html_tags()
{
global $allowedposttags; //tap into wordpress global array of allowed tags
global $allowedtags; //tap into wordpress global array of allowed tags
//$target
//$allowedtags[] = 'target';
$allowedtags['a'] = array('href' => true, 'title' => true, 'target' => true);
$allowedposttags['a'] = array('href' => true, 'title' => true, 'target' => true); //add target html tag in the style that wordpress expects
//var_dump($allowedtags);
}
add_action('init', 'add_required_html_tags', 10); //add action to initialise so we can access this tag everywhere.
The target is an attribute of the a tag so I’ve added it as an allowed attribute but it still isn’t working?