Support

Home Forums Event Espresso Premium Yoast SEO on event pages

Yoast SEO on event pages

Posted: May 18, 2019 at 6:36 am

Viewing 8 reply threads


neigd72

May 18, 2019 at 6:36 am

I’m trying to get the Yoast SEO options on event pages. I’ve followed the example here:

https://github.com/eventespresso/ee-code-snippet-library/blob/master/third-party-integration/tw_ee_load_yoast_seo_within_ee.php

When the admin page opens I get the following error (and no Yoast):

<b>Notice</b>: Undefined index: post_ID in <b>/nas/content/live/rustudios/wp-content/plugins/wordpress-seo-premium/premium/classes/premium-metabox.php</b> on line <b>192</b>

Any ideas? Thanks!


Tony

  • Support Staff

May 20, 2019 at 2:33 am

Hi there,

I’ve not tested the above snippet with Yoast’s premium version as I don’t use it.

If you’d like to send me a copy of the plugin I’ll take a quick look and see if it is something I can fix with the snippet, I’m guessing it’s pulling the current post_ID expected the default WordPress route.

You’ll need to host the .zip somewhere and post a link I can use to download it here. (You can set the post to private if preferred)


neigd72

May 20, 2019 at 2:38 am

This reply has been marked as private.


Tony

  • Support Staff

May 20, 2019 at 5:28 am

Also, even without out the code in functions.php it still gives the error, so that’s a red herring.

Yeah, in that case, it’s not the code, but placing that snippet in functions.php doesn’t work, you’ll need to add to a custom functions plugin, we have some documentation on creating one here:

https://eventespresso.com/wiki/create-site-specific-plugin-wordpress-site/


neigd72

May 20, 2019 at 7:53 am

I’ve followed those steps (taken the code out of functions.php and put into a customs function plug-in, and activated it) but I’m still getting the original error.


Tony

  • Support Staff

May 20, 2019 at 8:22 am

Which error?

Yoast isn’t loading on the event editor or you’re still getting the notice?


neigd72

May 20, 2019 at 9:09 am

Yoast is now loading, but I’m still getting the Yoast error. I guess it is their problem rather than yours though! I’ve emailed them – thank for the the help.


Tony

  • Support Staff

May 20, 2019 at 9:20 am

Yeah, it’s from a function within Yoast, this one to be exact:

/**
 * Retrieves the post ID from the globals.
 *
 * @codeCoverageIgnore
 *
 * @return int The post ID.
 */
protected function get_post_ID() {
	return $GLOBALS['post_ID'];
}

So they always expect $GLOBALS['post_ID'] to be set.

You can add something like:

add_action('admin_enqueue_scripts', 'ee_yoast_seo_post_id_notice', 2);
function ee_yoast_seo_post_id_notice() {
        global $post;
        // Add a missing 'post_ID' global for SEO Premium on when in event editor.
        if ($post instanceof WP_Post && $post->post_type === 'espresso_events' && ! isset($GLOBALS['post_ID'])) {
            $GLOBALS['post_ID'] = $post->ID;
        }
}

To the above snippet (outside of the first function) and that should stop it.


neigd72

May 20, 2019 at 11:11 am

That worked perfectly – thank you!

Viewing 8 reply threads

The support post ‘Yoast SEO on event pages’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso