Open thetwopct opened 4 years ago
For now, a quick workaround to restore the site is editing:
/plugins/wp-multilang/includes/integrations/class-wpm-yoast-seo.php
And commenting out line 311
if ( ! empty( $language['wpseo_og_locale'] ) ) {
// $wpseo_og->og_tag( 'og:locale:alternate', $language['wpseo_og_locale'] );
}
Or another solution to install Yoast 13.5 https://github.com/Yoast/wordpress-seo/releases/tag/13.5
thank you, @thetwopct ! you saved me several hours by finding the line. I don't know what does that line do, but I figured that I could add a safeguard without removing code, hence I present yo a workaround that does not remove functionality but it is a bit riskier:
if ( ! empty( $language['wpseo_og_locale'] ) && $wpseo_og!==null) {
$wpseo_og->og_tag( 'og:locale:alternate', $language['wpseo_og_locale'] );
}
I'm going to write down here if anything goes wrong with this approach.
edit: I have sent a pull request regarding this
Well the $wpseo_og global no longer exists in Yoast 14+ so it will always be null.
Need to move all references to the new Surfaces API
https://developer.yoast.com/blog/yoast-seo-14-0-using-yoast-seo-surfaces/
But their current documentation doesn't mention og locale alternate, so unsure of a fix right now
For Yoast 14+
use Yoast\WP\SEO\Presenters\Abstract_Indexable_Presenter;
// Creates an Opengraph alternate locale meta tag to be consumed by Yoast SEO // Requires Yoast SEO 14.0 or newer. final class WPML_ALTERNATE_LOCAL_PRESENTER extends Abstract_Indexable_Presenter { /**
@var string $locale */ private $locale;
/**
@param string $locale Facebook locale. */ public function __construct( $locale ) { $this->locale = $locale; }
/**
@return string */ public function present() { return sprintf( '', esc_attr( $this->get() ) ); }
/**
Add this class
//Class add alternate locale meta tag class SHDM_WPML {
/**
* Constructor.
*/
public function __construct() {
add_filter('wpseo_frontend_presenters', array($this, 'wpseo_frontend_presenters'));
}
/**
* Adds opengraph support for translations
*
* @param array $presenters An array of objects implementing Abstract_Indexable_Presenter
* @return array
*/
public function wpseo_frontend_presenters($presenters) {
$_presenters = array();
foreach ($presenters as $presenter) {
$_presenters[] = $presenter;
if ($presenter instanceof Yoast\WP\SEO\Presenters\Open_Graph\Locale_Presenter) {
foreach ($this->get_ogp_alternate_languages() as $lang) {
$_presenters[] = new WPML_ALTERNATE_LOCAL_PRESENTER($lang);
}
}
}
return $_presenters;
}
/**
* Get alternate language codes for Opengraph
*
* @return array
*/
protected function get_ogp_alternate_languages() {
global $wpseo_og;
$alternates = array();
$languages = array();
if ( is_singular() ) {
$languages = get_post_meta( get_the_ID(), '_languages', true );
} elseif ( is_category() || is_tax() || is_tag() ) {
$languages = get_term_meta( get_queried_object_id(), '_languages', true );
}
foreach ( wpm_get_languages() as $code => $language ) {
if ( ( $languages && ! isset( $languages[ $code ] ) ) || $code === wpm_get_language() ) {
continue;
}
if ( ! empty( $language['wpseo_og_locale'] ) ) {
$alternates[] = $language['wpseo_og_locale'];
}
}
// There is a risk that 2 languages have the same Facebook locale. So let's make sure to output each locale only once.
return array_unique($alternates);
}
} function run_shdm_wpml() { $wpml = new SHDM_WPML(); } run_shdm_wpml();
Fix of this has been added to Patch 2.4.2 here https://github.com/VaLeXaR/wp-multilang/pull/188
Hi @damircalusic, if I'm correct the patch has not been merged with the master right? How do I receive the patch for the plugin in wordpress exactly?
Hi @CXHub you can downlaod the verison 2.4.3 patch from here https://github.com/damircalusic/wp-multilang/tree/dc-patch-v.2.4.3
Warning to anyone upgrading to the latest Yoast, seems like there is a breaking change that took down my site:
`[30-Apr-2020 11:31:20 UTC] PHP Fatal error: Uncaught Error: Call to a member function og_tag() on null in /home/mywebsite/public_html/wp-content/plugins/wp-multilang/includes/integrations/class-wpm-yoast-seo.php:311 Stack trace:
0 /home/mywebsite/public_html/wp-includes/class-wp-hook.php(288): WPM\Includes\Integrations\WPM_Yoast_Seo->add_alternate_opengraph_locale()
1 /home/mywebsite/public_html/wp-includes/class-wp-hook.php(312): WP_Hook->apply_filters('', Array)
2 /home/mywebsite/public_html/wp-includes/plugin.php(544): WP_Hook->do_action(Array)
3 /home/mywebsite/public_html/wp-includes/plugin.php(660): do_action_ref_array('wpseo_opengraph', Array)
4 /home/mywebsite/public_html/wp-content/plugins/wordpress-seo/src/integrations/front-end/backwards-compatiblity.php(60): do_action_deprecated('wpseo_opengraph', Array, '14.0', 'wpseofrontend...')
5 /home/mywebsite/public_html/wp-includes/class-wp-hook.php(288): Yoast\WP\SEO\Integrations\Front_End\Backwards_Compatibility->call_wpseo_opengraph('')
6 /home/mywebsite/public_html/wp-includes/class-wp-hook.php in /home/mywebsite/public_html/wp-content/plugins/wp-multilang/includes/integrations/class-wpm-yoast-seo.php on line 311`