script: add OG in site
Mon Dec 11 2023 13:12:26 GMT+0000 (Coordinated Universal Time)
Saved by
@mubashir_aziz
// Update the custom field with the dynamic OG image URL
// function update_og_image_field($post_id) {
// if (has_post_thumbnail($post_id)) {
// $image_url = generate_dynamic_og_image($post_id); // Generate the dynamic OG image URL
// update_post_meta($post_id, 'og_image', $image_url);
// }
// }
// add_action('save_post', 'update_og_image_field');
// // Retrieve the OG image URL and include it in the <meta> tags
// function display_og_image() {
// if (is_singular()) {
// $post_id = get_queried_object_id();
// $og_image = get_post_meta($post_id, 'og_image', true);
// if (!empty($og_image)) {
// echo '<meta property="og:image" content="' . esc_url($og_image) . '">';
// }
// }
// }
// add_action('wp_head', 'display_og_image');
content_copyCOPY
Comments