?? Two steps forward, one step back. No worries.
It must be return $seotitle;
not echo! Remember though that $seotitle
as used here will be ANY title to ANY WP page that uses the header template. This is OK, but possibly a point of confusion.
The real issue as you have identified is getting your plugin to communicate with the ‘wp_title’ callback function. As much as we should avoid using globals, we likely have no alternative here. So go ahead and declare a global in your plugin. We can use the fact the global is set as a flag to to alter the page title. Since the ‘wp_title’ filter fires for any page request, to avoid cross talk, you must delay setting this global until just before your plugin’s page is output, and your ‘wp_title’ callback function must unset the global so that it is not mistakenly applied to another page.
Thus, part of the callback function portion of this scheme should look something like this:
global $AR_seo_title;
if(isset($AR_seo_title)) {
$seotitle = $AR_seo_title;
unset($AR_seo_title);
}
return $seotitle;
There may be more to this eventually, or that may be all of it, except for the function declaration and filter hook of course.
Again, be sure your plugin assigns a value to $AR_seo_title
as late as possible before the page is output.