Answer the question
In order to leave comments, you need to log in
Is it possible to give different opengraph tags depending on the parameters in the url on the same page?
Tell me, how can I make it so that different pictures are displayed in the header of the page in the open graf tag, depending on the parameter in the url? Those. site.ru/page?img=1, site.ru/page?img=2, etc.
This is necessary so that when a user shares the test result in a social network, different pictures are sucked.
Are there ready-made plugins? So that in the page settings you can load different pictures for different parameters in the url.
Answer the question
In order to leave comments, you need to log in
Here is a plugin that has filters for similar tasks:
https://wordpress.org/plugins/opengraph/faq/
In your case, it will be something like:
function my_og_{name}( ${name} ) {
$my_string = $_SERVER['QUERY_STRING']; // Взяли переменные из URL
parse_str( $my_string, $my_vars );
if ( 'var_value' === $my_vars['var_name'] ) {
// Тут подменяете нужное свойство (которое {name})
...
}
return ${name};
}
add_filter( 'opengraph_{name}', 'my_og_{name}' );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question