• Resolved jrvcosta

    (@jrvcosta)


    I need to insert an og:image (link) to all posts from a specific category. It would be nice to specify Image Width and Height too, which are the same (same image).

    Is there a way to do this in ‘bulk mode’ (maybe a SQL command?) instead of editing posts one by one?

    Thank you in advance!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Michael Torbert

    (@hallsofmontezuma)

    WordPress Virtuoso

    You can use our API filter hook aiosp_opengraph_meta to edit social meta programatically.
    https://semperplugins.com/documentation/aiosp_opengraph_meta/

    Thread Starter jrvcosta

    (@jrvcosta)

    Thanks Michael!

    I tried this hook. It works fine for url (as shown in the example) but not for og:image. At least not the way I tried:

    if( $field == 'image' ) $value = 'https://mynewurl.com';
            return $value;

    This return nothing. What field name should I use for Open Graph images?

    • This reply was modified 5 years ago by jrvcosta.
    Plugin Author arnaudbroes

    (@arnaudbroes)

    @jrvcosta the field name is thumbnail and twitter_thumbnail for the Twitter image.

    Thread Starter jrvcosta

    (@jrvcosta)

    Thank you very much! Now it worked.

    I just don’t appreciate one thing: this hook override all social settings. If I save a different og:image link in All in One SEO Image Settings (on a particular post/page) this will be ignored. I would prefer if it change settings only if those field settings were empty in a post/page.

    Michael Torbert

    (@hallsofmontezuma)

    WordPress Virtuoso

    That can be done with the code using the filter. The filter hook is just a tool, how you want to customize the usage of it is up to you.

    Thread Starter jrvcosta

    (@jrvcosta)

    I understand Michael. Thank you again.

    Just one more question, please: how do I tell the filter to fill a field name only if it’s empty? Certainly $field == '' will not work because $field is already 'thumbnail'.

    • This reply was modified 5 years ago by jrvcosta.
    • This reply was modified 5 years ago by jrvcosta.
    Plugin Author arnaudbroes

    (@arnaudbroes)

    @jrvcosta just check if $value is empty. For the OG:image you’ll also want to check if the it isn’t the default image.

    Thread Starter jrvcosta

    (@jrvcosta)

    All Ok now! Thank you, guys!
    And to share with other colleagues, here′s the code that works for me:

    
    add_filter('aiosp_opengraph_meta','aioseop_change_settings', 10, 5);
    function aioseop_change_settings ( $value, $type, $field, $v, $extra_params ) 
    {    
        if ( in_category('my-category') ) {
        if (!has_post_thumbnail() && $field == 'thumbnail' && $value == '') $value = 'https://www.mydomain.com/wp-content/uploads/new-og-image.jpg';
    	if ( $field == 'width' && $value == '' ) $value = '1200';
    	if ( $field == 'height' && $value == '' ) $value = '630';
            return $value;
        }
    }
    
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Specifying og:image in several posts’ is closed to new replies.