{"id":1014,"date":"2025-03-24T14:28:16","date_gmt":"2025-03-24T14:28:16","guid":{"rendered":"https:\/\/wpgeodirectory.com\/documentation\/article\/add-oggimage-meta-tag-with-the-default-image-when-a-geodir-cpt-has-no-featured-image\/"},"modified":"2025-04-03T15:24:38","modified_gmt":"2025-04-03T14:24:38","slug":"add-oggimage-meta-tag-with-the-default-image-when-a-geodir-cpt-has-no-featured-image","status":"publish","type":"gd_place","link":"https:\/\/wpgeodirectory.com\/documentation\/article\/code-snippets\/add-oggimage-meta-tag-with-the-default-image-when-a-geodir-cpt-has-no-featured-image\/","title":{"rendered":"Add ogg:image meta tag with the default image when a Geodir cpt has no featured image"},"content":{"rendered":"\n<p>When a Geodir cpt has no featured image, try to add the og:image meta tag if the cpt has a default image<\/p>\n\n\n\n<div class=\"wp-block-blockstrap-blockstrap-widget-alert d-flex align-items-center fade show alert alert-info mb-3\" role=\"alert\"><span class=\"fas fa-info-circle me-2\"><\/span><span class=\"flex-grow-1\">We recommend using the <a href=\"https:\/\/wpgeodirectory.com\/documentation\/article\/useful-plugins\/code-snippets-plugin\/\">Code Snippets<\/a> plugin to add snippets to your site.&nbsp;<\/span><\/div>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-php\">add_filter( &#039;geodir_details_facebook_og&#039;, function( $fcb_og, $post ) {\n    if (\n        ! empty( $fcb_og ) ||\n        ! isset( $post-&gt;post_type ) ||\n        ! is_singular( geodir_get_posttypes() )\n    ) {\n        return $fcb_og;\n    }\n\n    $post_type_obj = geodir_post_type_object( $post-&gt;post_type );\n\n    if ( empty( $post_type_obj-&gt;default_image ) ) return $fcb_og;\n\n    $url = wp_get_attachment_url( $post_type_obj-&gt;default_image );\n    return $url ? &#039;&lt;meta property=&quot;og:image&quot; content=&quot;&#039; . esc_url_raw( $url ) . &#039;&quot;\/&gt;&#039; : $fcb_og;\n}, 99, 2 );<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>When a Geodir cpt has no featured image, try to add the og:image meta tag if the cpt has a default image<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"article\/tags":[],"article\/categories":[211,433],"class_list":["post-1014","gd_place","type-gd_place","status-publish","hentry","gd_placecategory-tips-tricks-more","gd_placecategory-code-snippets"],"_links":{"self":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/1014","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article"}],"about":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/types\/gd_place"}],"author":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/comments?post=1014"}],"version-history":[{"count":0,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/1014\/revisions"}],"wp:attachment":[{"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/media?parent=1014"}],"wp:term":[{"taxonomy":"gd_place_tags","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/tags?post=1014"},{"taxonomy":"gd_placecategory","embeddable":true,"href":"https:\/\/wpgeodirectory.com\/documentation\/wp-json\/wp\/v2\/article\/categories?post=1014"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}