I am working on a WordPress plug-in which automatically generates posts from a user´s facebook events (this is specifically for a single website, not trying to publish this).
So the post generating and “posting” really do work fine. I use php-class-html-generator for generating a posts mark-up. It basically looks like this:
$post_desc = HtmlTag::createElement('div');
$post_desc -> addClass("af_post_content");
$post_desc -> setText($event_desc);
...
$post = array(
'post_title' => $name,
'post_content' => $post_desc -> toString(),
'post_status' => 'publish',
'post_category' => $category_id
);
...
wp_insert_post($my_post);
When I look at the post´s mark-up (in the back-end or front-end) everything is alright.
Now to my problem: As these post represent “events” I want to add rich snippet mark-up to the post. Declare them as a event, add start time, location with postal address(https://schema.org/Event). The issue is, if I add the mark-up like this:
$post_desc -> set("itemscope", " ");
$post_desc -> set("itemtype", "http://schema.org/Event");
The “itemscope” and “itemtype” won´t show up in the post´s mark-up.
I tried this outside of WordPress with a single “hello world”-example to test if the php-class-html-generator is the issue, but it correctly generates the attributes.
<?php
require_once ('HtmlTag.class.php');
$post_desc = HtmlTag::createElement('div');
$post_desc -> addClass("af_post_content");
$post_desc -> set("itemscope", " ");
$post_desc -> setText("Hello world!");
echo $post_desc;
?>
Source looks like this:
<div itemscope=" " class="af_post_content">Hello world!</div>
So does WordPress suppress some attributes/tags in a post´s mark-up? I had a similiar problem when generating a <table>
tag. If so, can I somehow allow these tags?
There are some plug-ins out there for rich snippets, but these mostly handle mark-up change when manually creating a post.
Thank you!
I wouldn’t recommend any schema.org specific plugins, as these only bring noise. At least that was my experience.
Not sure if I can help for the specific problem you have, but you can at least try using Yoast plugin https://yoast.com/wordpress/, which is the SEO plugin that also manages schema.org markup in general.
I know it is not an out-of-the-box solution, but sometimes solutions that sound simple, like this one, may help.