For first let me introduce what I've already discovered.
I don't know how Yoast calculates the permalink but it's non standard and that fact creates a lot of problems.
There are some filters to force Yoast to use the correct permalink:
add_filter('wpseo_canonical', array(__CLASS__, 'yoast_change_seo_canonical'), 1, 1 );
add_filter('wpseo_opengraph_url', array(__CLASS__, 'yoast_change_seo_opengraph_url'), 10);
add_filter('wpseo_schema_article', array(__CLASS__, 'example_change_article') );
add_filter('yoast_seo_development_mode', '__return_true' );
public static function yoast_change_seo_canonical( $canonical )
{
if ( is_single() )
{
return get_permalink();
}
else
return $canonical;
}
public static function yoast_change_seo_opengraph_url( $canonical )
{
return get_permalink();
}
function example_change_article( $data )
{
//YoastSEO()->context_memoizer;
YoastSEO()->meta->for_current_page()->canonical = get_permalink();
YoastSEO()->meta->for_current_page()->open_graph_url = get_permalink();
}
The last one doesn't work as I would expect.
Any suggestion? I've tried both to change the data in the context / memoizer, but also to use the filters.