Support » Plugin: All in One SEO Pack » Specifying og:image in several posts

  • Resolved Jose Costa

    (@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)
  • Plugin Contributor 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/

    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 = 'http://mynewurl.com';
            return $value;

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

    • This reply was modified 1 month, 3 weeks ago by Jose Costa.
    Plugin Contributor arnaudbroes

    (@arnaudbroes)

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

    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.

    Plugin Contributor 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.

    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 1 month, 2 weeks ago by Jose Costa.
    • This reply was modified 1 month, 2 weeks ago by Jose Costa.
    Plugin Contributor 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.

    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)
  • You must be logged in to reply to this topic.