Creating the Difference

Create Google Structured Data for Events Manager dynamically

Posted on: 26-09-2018  No Comments
Categories: HTML, PHP, Snippets Tags: , , ,

How to create a one-time code for all your events:
Past, present, future & with or without bookings.

NOTE: Ticket prices are an Events Manager Pro feature. If you are only using the free plugin, you need to take those parts out of the snippets!

Telling Google about your events is very important. Of course you want Google to display the correct information, so anyone who finds you knows exactly what you are offering.

On the Google Developer website is says that they will want you to provide this info using jSon mark-up. But when you’re using Events Manager (Pro), it’s much better to not! πŸ˜›
Why? Json mark-up does not support the extremely handy conditional placeholders Events Manager offers.

For example:
With the conditional placeholders you can tell Google that the event is sold out, or cancelled etc. Also, if the event has passed, Google will not automatically change the structured data. But with the method below, it will be automatically updated (if needed) every time Google crawls your blog. And you won’t have to alter any of the code for that.

Step 1: Copy & Paste in WordPress.

In your WordPress Admin Dashoard, paste this part at the top of Events → Settings → Formatting → Single event page format. (So above your current mark-up.) Don’t worry: this whole section will not output anything to your visitors, so your lay-out remains 100% untouched. πŸ™‚
Don’t forget to change [YOUR COMPANY] to your personal info.

By pasting this in the Single Event Page Format section, the code will automatically apply to every event on your blog. The conditional placeholders will automatically output the correct data for that specific event.

If you are not using Events Manager Pro, but the free version, please replace #_ccTicketPrice with a hard-coded value, like: 10.00

Step 2: Edit if needed.

As you can see, there are embedded (multi-level) conditional placeholders. By default Events Manager only supports 1 level. To enable multi-level conditional placeholders, add this to your wp-config.php file (“4” is the number of levels you want to enable):

Step 3: Restore original published date.

By default Events Manager alters the WordPress published date to the event date. For Google we will need the actual published date, because that is the date we will start telling Google about our event and also when the tickets become available. So we simply remove the alteration. It does not have real benefits anyway. So, I personally do not understand why the EM Devs even put it in. πŸ˜›

Add this to your functions.php:Click here to learn how to safely add your code to WordPress.

Note:
With this filter enabled, Google will get strange data. Say you publish the event on 01/01/2018, but it takes place on 31/03/2018. If Google crawls your blog on 01/02/2018, you are actually telling Google: “Hey, here’s a an event I will publish two months from now, but you may read it anyway.”

Step 4: Create custom placeholders.

Events Manager does not provide any placeholders to output the ticket price without the currency formatting, but Google will want that. So, in the end you will need these custom placeholders:
#_ccTicketPrice, #_ccTicketName, #_ccTicketStart & #_ccTicketEnd.

Add this snippet to your functions.php:Click here to learn how to safely add your code to WordPress.
If you are not using Events Manager Pro, but the free version, please delete lines 11 – 20 below.

Step 5: Test your mark-up.

After all that, go to the Google Structured Data Test Tool to test your mark up. πŸ™‚

Step : Let me know what you think.

Please read the Comment Policy before commenting.

⇐ Previous
Next ⇒