N
N
Nikita Borzenkov2015-10-21 12:51:02
In contact with
Nikita Borzenkov, 2015-10-21 12:51:02

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

2 answer(s)
I
Igor Vorotnev, 2015-10-21
@BashXP

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}' );

PS: I haven't tested it, but it should work. If something goes wrong - write, we'll figure it out.

A
Andrew, 2015-10-21
@R0dger

implement it in native code via $_GET['img']
there is nothing military there, just don't forget to check if this parameter exists at the very beginning.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question