Using Filter to Change tags

On our site we have a people depicted field that has linked searches that find all other records with that person. In order to improve the visibility of these search result pages, I'd like to add the person's name to the title tag of these browse pages. However, I don't want to add info to the <title> for all search results.

Here's a rough sketch of what I'll add to my custom.php

add_filter('display_setting_site_title', 'my_plugin_site_title');
function my_plugin_site_title($title)
    if ($bodyclass =='browse' && $_GET element_id==90){ //90 is the element_id of my people depicted field
return "$title | $_GET search terms"

I know the code is not correct, but generally is this the right way to add additional info to the <title>?


Syntax aside, that would work.

If this is just one site and you control the theme, it might be just as easy to alter the code in common/header.php that creates the title tag in the first place, then you don't need to rely on fudging text onto the site title.

Cool. So syntax aside would something like this in the header.php file work?

<?php if ($bodyclass =='browse' && $_GET element_id==90){ $title.= "$_GET search terms"}

echo settings('site_title'); echo isset($title) ? ' | ' . strip_formatting($title) : ''; ?></title>


Ok so here's what I have in my header.php file:

if ($bodyclass=='browse' && isset($_GET['advanced'])) {
if ($advancedsearch[0]['element_id']==91&&$advancedsearch[0]['type']=='contains'){
$title.=" - ";
if (strpos($personName,',')!==false){
if (strpos($firstMiddle,',')!==false){
$personName=$firstMiddle.' '.$lastName.$suffix;}
echo settings('site_title'); echo isset($title) ? ' | ' . strip_formatting($title) : ''; ?>

It checks to see if I'm on the search results browse page, and if the advanced search has been set. Then it determines if element_id 91 is used, and if it is using 'contains'. Then since most of our people depicted names are in the format "Last, First Middle, (suffix)", it checks to see if there is a comma(s), and if there is, it rearranges the name to "First Middle Last" or "First Middle Last, suffix. It then puts the name into the <title>.

Any suggestions for improving or condensing this code are welcomed. Also I have switched the people depicted name to "First Middle Last" thinking that is how people are more likely to search for a name in Google. Do you think that would help vs having "Last, First Middle" in the <title>?

Thanks again,