Trying to modify the output of the WP_Title through a custom post type with a filter. I've had no issues doing it to the_title but I assume as the wp_title function is called through the header it's the problem and I'm missing something simple.
What I want to do is change the output of the listing pages with some of the meta-box data into the pages title tag. What I've set up so far is as follows:
add_filter('wp_title', 'dw_listing_title', 10, 2);
function dw_listing_title($title, $id) {
if('sp_property' == get_post_type($id) )
$address = get_post_meta($id, 'Address', false );
$city = get_post_meta($id, 'City', false );
$listingID = get_post_meta($id,"ListingId");
$title = $address[0] . ', ' . $city[0] . ' Listing: ' . $listingID[0];
return $title;
}
This alters the title just fine when I switch wp_title to the_title. I think I need to add a global variable to tie into it but when I tried adding global $post (or $wp_query) nothing changed.
Also Im not sure if Yoast SEO would cause problems with trying to change this? I dont have any data entered into the input boxes though.
EDIT:: So after turning off the Yoast SEO plugin the wp_title is being rewritten, the problem now is the meta box values being displayed.