{"action":"created","issue":{"url":"https://api.github.com/repos/Yoast/wordpress-seo/issues/392","labels_url":"https://api.github.com/repos/Yoast/wordpress-seo/issues/392/labels{/name}","comments_url":"https://api.github.com/repos/Yoast/wordpress-seo/issues/392/comments","events_url":"https://api.github.com/repos/Yoast/wordpress-seo/issues/392/events","html_url":"https://github.com/Yoast/wordpress-seo/issues/392","id":22450920,"number":392,"title":"wpseo_opengraph_image not working properly","user":{"login":"palmjack","id":3027293,"avatar_url":"https://avatars.githubusercontent.com/u/3027293?v=3","gravatar_id":"","url":"https://api.github.com/users/palmjack","html_url":"https://github.com/palmjack","followers_url":"https://api.github.com/users/palmjack/followers","following_url":"https://api.github.com/users/palmjack/following{/other_user}","gists_url":"https://api.github.com/users/palmjack/gists{/gist_id}","starred_url":"https://api.github.com/users/palmjack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/palmjack/subscriptions","organizations_url":"https://api.github.com/users/palmjack/orgs","repos_url":"https://api.github.com/users/palmjack/repos","events_url":"https://api.github.com/users/palmjack/events{/privacy}","received_events_url":"https://api.github.com/users/palmjack/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2013-11-11T14:20:57Z","updated_at":"2015-10-08T17:40:46Z","closed_at":"2014-08-08T20:24:21Z","body":"I'm trying to hook to wpseo_opengraph_image to get the image stored in post_meta table and display its url in og:image tag, but it seems not to work correctly.\r\n\r\nI have to add that I'm using post_thumbnails, for some posts, but not the ones I want to use wpseo_opengraph_image hook.\r\n\r\nHere's my code (for post_type product):\r\n```php\r\nadd_filter('wpseo_opengraph_image', 'og_image');\r\n\r\nfunction og_image($img)\r\n{\r\n\t$post = get_post();\r\n\r\n\tif(get_post_type($post->ID) == \"product\")\r\n\t{\r\n\t\t$meta = get_post_meta($post->ID, 'wpcf-square-picture', true);\r\n\t\t$attachment_id = get_attachment_id_from_src($meta);\r\n\t\tif($attachment_id)\r\n\t\t{\r\n\t\t\t$img = wp_get_attachment_image_src($attachment_id, 'full');\r\n\t\t\treturn $img[0];\r\n\t\t}\r\n\t}\r\n}\r\n```\r\nI think that the problem is this function https://github.com/Yoast/wordpress-seo/blob/master/frontend/class-opengraph.php#L311\r\nIt checks post_thumbnail, post_content, but what if none of them contains the image?\r\n\r\nI used the code below to make it work:\r\n```php\r\nadd_filter('wpseo_pre_analysis_post_content', 'add_custom_content');\r\n\r\nfunction add_custom_content($content)\r\n{\r\n\t$post = get_post();\r\n\r\n\tif(get_post_type($post->ID) == \"product\")\r\n\t{\r\n\t\t$meta = get_post_meta($post->ID, 'wpcf-square-picture', true);\r\n\t\t$attachment_id = get_attachment_id_from_src($meta);\r\n\t\tif($attachment_id)\r\n\t\t{\r\n\t\t\t$img = wp_get_attachment_image_src($attachment_id, 'full');\r\n\t\t\treturn $content . '<img src=\"' . $img[0] . '\" />';\r\n\t\t}\r\n\t}\r\n\r\n\telse\r\n\t{\r\n\t\treturn $content;\r\n\t}\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/Yoast/wordpress-seo/issues/comments/146634436","html_url":"https://github.com/Yoast/wordpress-seo/issues/392#issuecomment-146634436","issue_url":"https://api.github.com/repos/Yoast/wordpress-seo/issues/392","id":146634436,"user":{"login":"andreasomovigo","id":8368596,"avatar_url":"https://avatars.githubusercontent.com/u/8368596?v=3","gravatar_id":"","url":"https://api.github.com/users/andreasomovigo","html_url":"https://github.com/andreasomovigo","followers_url":"https://api.github.com/users/andreasomovigo/followers","following_url":"https://api.github.com/users/andreasomovigo/following{/other_user}","gists_url":"https://api.github.com/users/andreasomovigo/gists{/gist_id}","starred_url":"https://api.github.com/users/andreasomovigo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andreasomovigo/subscriptions","organizations_url":"https://api.github.com/users/andreasomovigo/orgs","repos_url":"https://api.github.com/users/andreasomovigo/repos","events_url":"https://api.github.com/users/andreasomovigo/events{/privacy}","received_events_url":"https://api.github.com/users/andreasomovigo/received_events","type":"User","site_admin":false},"created_at":"2015-10-08T17:40:46Z","updated_at":"2015-10-08T17:40:46Z","body":"Sorry jdevalk, I'm too having troubles with this filter..do you mean:\r\n\r\n\r\nfunction AS_change_opengraph_img( $img ) {\r\n    if(is_home() || is_front_page())\r\n        return 'http://www.phifoundation.com/wp-content/uploads/2015/08/slide2.jpg';\r\n}\r\n\r\nadd_filter('wpseo_opengraph_image ', 'AS_change_opengraph_img', 10, 1 );\r\n\r\nwhy it does'nt work?\r\n\r\nthankyou"}}