/** * 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; }); // 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; }); // 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; }); // 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; }); // Remove any conflicting title filters remove_all_filters('wp_title'); remove_all_filters('pre_get_document_title'); remove_all_filters('document_title_parts'); // Add direct title output in head section 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 '' . esc_html($title) . '' . PHP_EOL; echo '' . PHP_EOL; echo '' . PHP_EOL; } } }, 1);