/** * Plugin Name: Creative Islands Title Fix * Description: Fixes the title format for Creative Islands to include the island code * Version: 1.0 * Author: Your Name */ // Register the island_code variable with Rank Math add_filter('rank_math/vars/island_code', function($value) { if (is_singular('creative_island')) { $island_code = get_post_meta(get_the_ID(), '_island_code', true); return $island_code ? $island_code : ''; } return $value; }); // Remove any conflicting title filters first remove_all_filters('wp_title'); remove_all_filters('pre_get_document_title'); remove_all_filters('document_title_parts'); remove_all_filters('rank_math/frontend/title'); remove_all_filters('rank_math/opengraph/facebook/og_title'); remove_all_filters('rank_math/twitter/title'); // Set the title format for creative islands add_filter('rank_math/frontend/title', function($title) { if (is_singular('creative_island')) { $island_code = get_post_meta(get_the_ID(), '_island_code', true); if ($island_code) { return get_the_title() . ' - ' . $island_code; } } return $title; }, 999); // Set OpenGraph title format add_filter('rank_math/opengraph/facebook/og_title', function($title) { if (is_singular('creative_island')) { $island_code = get_post_meta(get_the_ID(), '_island_code', true); if ($island_code) { return get_the_title() . ' - ' . $island_code; } } return $title; }, 999); // Set Twitter title format add_filter('rank_math/twitter/title', function($title) { if (is_singular('creative_island')) { $island_code = get_post_meta(get_the_ID(), '_island_code', true); if ($island_code) { return get_the_title() . ' - ' . $island_code; } } return $title; }, 999); // Add direct title output in head section as a fallback add_action('wp_head', function() { if (is_singular('creative_island')) { $island_code = get_post_meta(get_the_ID(), '_island_code', true); if ($island_code) { $title = get_the_title() . ' - ' . $island_code; echo '