function add_custom_open_graph_tags() { // Only run on single posts, pages, or the homepage if ( is_singular() ) { global $post; setup_postdata( $post ); $og_title = esc_attr( get_the_title() ); $og_url = esc_url( get_permalink() ); $og_description = esc_attr( wp_strip_all_tags( get_the_excerpt() ) ); $og_site_name = esc_attr( get_bloginfo( 'name' ) ); $og_type = 'article'; // Get featured image, default to a fallback if none exists if ( has_post_thumbnail( $post->ID ) ) { $og_image = esc_url( wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' )[0] ); } else { $og_image = 'https://your-domain.com'; // Change this line } } elseif ( is_home() || is_front_page() ) { // Homepage defaults $og_title = esc_attr( get_bloginfo( 'name' ) ); $og_url = esc_url( home_url() ); $og_description = esc_attr( get_bloginfo( 'description' ) ); $og_site_name = esc_attr( get_bloginfo( 'name' ) ); $og_type = 'website'; $og_image = 'https://your-domain.com'; // Change this line } else { return; // Skip archives, 404s, etc. } // Output the clean HTML Meta Tags into the header echo "\n\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; // Forces Arabic localized behavior } add_action( 'wp_head', 'add_custom_open_graph_tags', 5 );