frontity / wp-plugins

» Frontity - Create amazing sites using WordPress & React

Home Page:https://frontity.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

REST API - Head Tags doesn't work with Yoast SEO ^14.0 [5pt]

DAreRodz opened this issue · comments

Bug report

Our plugin integration with the Yoast plugin stopped working since the release of its 14.0 version.

They made a major release and they have practically rewritten the whole code; all the functions and classes we are using are now deprecated. Having said that, we should rewrite setup and reset functions in the Yoast integration (nothing of the following code is valid):

/**
* Setup function.
*/
public function setup() {
// Create a new instance of WPSEO_Frontend if it's not created yet.
WPSEO_Frontend::get_instance();
// Call Yoast init function.
wpseo_frontend_head_init();
}
/**
* Reset function.
*/
public function reset() {
// Get current instance.
$wp_seo = WPSEO_Frontend::get_instance();
// Remove wp_seo actions added to 'wp_head' hook.
remove_action( 'wp_head', array( $wp_seo, 'front_page_specific_init' ), 0 );
remove_action( 'wp_head', array( $wp_seo, 'head' ), 1 );
// Remove all actions from WPSEO hooks.
remove_all_actions( 'wpseo_head' );
remove_all_actions( 'wpseo_json_ld' );
remove_all_actions( 'wpseo_opengraph' );
// Remove WPSEO_Twitter instance.
WPSEO_Twitter::$instance = null;
// Reset WPSEO plugin.
$wp_seo->reset();

Expected behavior

I should include the Yoast meta tags in the head_tags field for all entities, not just for the first one.

Observed behavior

It only works for the first entity.

The current code is removing all hooks attached to the wpseo_head action in the reset function:

and calling this the Yoast reset function after that

which was adding all hooks once again, apart from other stuff. That function simply does nothing since the 14.0 version of Yoast SEO.

Steps involved to reproduce the problem

Just install the latest version of both Head Tags and Yoast SEO plugins.

Possible solution

I don't see an easy solution in this case. We will have to study the Yoast SEO code in-depth and look for public functions and classes we could use to get the meta tags rendered in the wp_head action for a given WP_Query.

At least their code has improved a lot! 😄

@DAreRodz, is there a way to distinguish between the versions of Yoast to keep the current integration for Yoast v13 and lower and create a new one for v14 and higher?

Instead of fixing it in the Head Tags plugin, as we have to change the whole implementation, we're planning to create a @frontity/yoast package that we'll get the info from the Yoast REST API fields. This way, users with Yoast ^14.0 should use this new package, and the ones using older versions, can install the Head Tags plugin.