Here is the fixed amt_get_allowed_html_kses()
which allows the meta
and link
elements by default and allows filtering of the supported elements.
It would be nice if you could test this (whenever possible) with the latest version of Add-Meta-Tags and confirm that it works with the link elements you use. If testing is not possible, it’s fine.
function amt_get_allowed_html_kses() {
// Store supported global attributes to an array
// As of https://www.w3schools.com/tags/ref_standardattributes.asp
$global_attributes = array(
'accesskey' => array(),
'class' => array(),
'contenteditable' => array(),
'contextmenu' => array(),
// 'data-*' => array(),
'dir' => array(),
'draggable' => array(),
'dropzone' => array(),
'hidden' => array(),
'id' => array(),
'lang' => array(),
'spellcheck' => array(),
'style' => array(),
'tabindex' => array(),
'title' => array(),
'translate' => array()
);
// Construct an array of valid elements and attributes
$valid_elements_attributes = array(
// As of https://www.w3schools.com/tags/tag_meta.asp
// plus 'itemprop' and 'property'
'meta' => array_merge( array(
'charset' => array(),
'content' => array(),
'http-equiv' => array(),
'name' => array(),
'scheme' => array(),
'itemprop' => array(), // schema.org
'property' => array() // opengraph and others
), $global_attributes
),
// As of https://www.w3schools.com/tags/tag_link.asp
'link' => array_merge( array(
'charset' => array(),
'href' => array(),
'hreflang' => array(),
'media' => array(),
'rel' => array(),
'rev' => array(),
'sizes' => array(),
'target' => array(),
'type' => array()
), $global_attributes
)
);
// Allow filtering of $valid_elements_attributes
$valid_elements_attributes = apply_filters( 'amt_valid_full_metatag_html', $valid_elements_attributes );
return $valid_elements_attributes;
}
To support more elements you need to add a filtering function that extends the list of the valid elements and attributes in your functions.php
file of your theme. For example, in order to add the title
element, so that you can put a line like <title>my test title</title>
in the ‘Full meta tags’ box, you should add the following code to functions.php
:
// Adds the 'title' element to the valid html elements for the full meta tags box
function extend_full_metatag_valid_elements( $valid_elements ) {
// Construct the title element array (key: element name, value: array of valid attributes)
$title_element = array( 'title' => array() );
// Append the 'title' element to the valid elements
$valid_elements = array_merge( $valid_elements, $title_element);
return $valid_elements;
}
add_filter( 'amt_valid_full_metatag_html', 'extend_full_metatag_valid_elements', 10, 1 );
Hope these help. Thanks for your feedback! ??
George