MISSION_LOG

BACK TO ARCHIVE
TRANSMISSION_ID: 2025-01-16-illphated-wp-x-twitter-ogdata-override

ILLPHATED WP X-TWITTER OGDATA OVERRIDE

DATE: 2025-01-16 15:18:55

STATUS: PUBLISHED

AUTHOR: illphated

// Save custom meta data function custom_og_override_save_meta_data($post_id) { // Verify nonce if (!isset($_POST['custom_og_override_nonce']) || !wp_verify_nonce($_POST['custom_og_override_nonce'], 'custom_og_override_save')) { return; }

// Save OG title if (isset($_POST['custom_og_title'])) { update_post_meta($post_id, '_custom_og_title', sanitize_text_field($_POST['custom_og_title'])); }

// Save OG description if (isset($_POST['custom_og_description'])) { update_post_meta($post_id, '_custom_og_description', sanitize_textarea_field($_POST['custom_og_description'])); } } add_action('save_post', 'custom_og_override_save_meta_data');

// Filter the Yoast SEO output for OG tags function custom_og_override_filter($og_tag_value, $presentation, $args) { // Check if the post has custom OG values $post_id = get_the_ID(); $custom_og_title = get_post_meta($post_id, '_custom_og_title', true); $custom_og_description = get_post_meta($post_id, '_custom_og_description', true);

// Override OG title if ($args->name === 'og:title' && !empty($custom_og_title)) { return $custom_og_title; }

// Override OG description if ($args->name === 'og:description' && !empty($custom_og_description)) { return $custom_og_description; }

return $og_tag_value; } add_filter('wpseo_frontend_presentation', function($presentation) { $presentation->open_graph_title = apply_filters('custom_og_override_filter', $presentation->open_graph_title, $presentation, (object)['name' => 'og:title']); $presentation->open_graph_description = apply_filters('custom_og_override_filter', $presentation->open_graph_description, $presentation, (object)['name' => 'og:description']); return $presentation; });

END OF TRANSMISSION // ILLPHATED.COM