Skip to content

Instantly share code, notes, and snippets.

@rosshanney
Last active October 3, 2018 16:28
Show Gist options
  • Save rosshanney/5425930 to your computer and use it in GitHub Desktop.
Save rosshanney/5425930 to your computer and use it in GitHub Desktop.
Add the itemprop, itemscope and itemtype attributes, and the meta tag to the list of allowed tags / attributes
<?php
/*
Plugin name: Add microdata stuff to list of allowed tags
*/
function gce_alter_allowed_tags() {
global $allowedposttags;
$microdata_atts = array( 'itemprop' => true, 'itemscope' => true, 'itemtype' => true );
$allowedposttags['div'] += $microdata_atts;
$allowedposttags['a'] += $microdata_atts;
$allowedposttags['img'] += $microdata_atts;
$allowedposttags['span'] += array( 'content' => true) + $microdata_atts;
$allowedposttags['meta'] = array( 'content' => true ) + $microdata_atts;
$allowedposttags['time'] = array( 'datetime' => true ) + $microdata_atts;
}
add_action( 'plugins_loaded', 'gce_alter_allowed_tags' );
@horizon89
Copy link

This is really useful because most people are worried about microdata being striped from the HTML editor / TinyMCE. The reality is that as more and more of us will be using the REST requests to communicate with wordpress, we'll still stumble on the problem.

Note that this works even if your html data is coming via WP REST API.

THANKS SO MUCH !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment