Since you’re using AIOSEO, you can use this filter to change the title dynamically – https://semperplugins.com/documentation/aioseop_title/
Using the AIO filter mentioned, you can get the passed season ID from $_GET['seasonid']
. You filter callback should verify the array key exists before trying to use it. If the season ID is always an integer value, type cast the value with (int)
before using it to ensure no malicious code was included with the passed value.
Awesome thanks guys this gives me a great place to start!!
Thanks guys, I was actually able to do it using the AIO filter and a reply to a post I made about changing a page title 6 years ago! HAHA. I combined them and it works. It looks like this. Appreciate the help!
add_filter( 'aioseop_title', 'change_wordpress_seo_title' );
function change_wordpress_seo_title( $title ){
$season = ( $_GET['seasonid'] ) ? $_GET['seasonid'] : '';
if ( $season ) $season = ' - 20' . substr($season,0,2) . '-' . substr($season,2,2);
return $title . $season;
}
-
This reply was modified 3 years, 7 months ago by lakerstats.
Just one final follow up. This is what I ended up doing based on the variable pulled by the page. Hope it provides some information for anyone in the future who may have this issue. Thanks for all the help!
add_filter( 'aioseop_title', 'change_wordpress_seo_title' );
function change_wordpress_seo_title( $title ){
$season = ( $_GET['seasonid'] ) ? $_GET['seasonid'] : '';
$pname = ( $_GET['pname'] ) ? $_GET['pname'] : '';
$date = ( $_GET['date'] ) ? $_GET['date'] : '';
if ($date) {
$date = date( "F j, Y", strtotime( $date ) );
return $date . ' ' . '-' . ' ' . $title;
}
if ($season) {
if ($season < 4000) $season = '20' . substr($season,0,2) . '-' . substr($season,2,2) . ' - ';
if ((substr($season, 0,1) > "3") && (substr($season, 0,1) <= "9")) $season = '19' . substr($season,0,2) . '-' . substr($season,2,2) .
' - ';
return $season . $title;
}
if ($pname) {
$pname = explode('_',$pname);
$fname = $pname[0];
$lname = $pname[1];
$suffix = $pname[2];
$suffix = ucfirst($suffix);
if (strpos($suffix, 'Ii') === 0) $suffix = II;
if (strpos($suffix, 'Jr') === 0) $suffix = "Jr.";
$suffix = " $suffix";
$lname = ucfirst($lname);
if (strpos($lname, 'Mc') === 0) {
$lname ='Mc' . ucwords(substr($lname, 2, strlen($lname)));
}
$lname = preg_replace("/(\w+)/e","ucfirst('\\1')", $lname);
if ($lname === Oneal) $lname = "O\'Neal";
if ($lname === Oshea) $lname = "O\'Shea";
$fname = ucfirst($fname);
if ($fname === Lebron) $fname = LeBron;
if ($fname === Javale) $fname = JaVale;
if ($fname === Marshon) $fname = MarShon;
if ($fname === Jr) $fname = "J.R.";
if ($fname === Dangelo) $fname = "D\'Angelo";
if ($fname === Cj) $fname = "C.J.";
if ($fname === Dj) $fname = "D.J.";
if ($fname === Ac) $fname = "A.C.";
if ($fname === Mccoy) $fname = McCoy;
return $fname . ' ' . $lname . $suffix . ' - ' . $title;
}
else return $title;
}