• Hi all,

    Yes I am using an older verison of WP that I like and don’t want to switch from. I know you’re going to tell me to, but currently that’s not going to happen. 🙂 So with that in mind.

    I have looked up ways to do this and I just can’t quite understand how to make it work for me. I have a page on my site, take this one for example.’
    http://www.lakerstats.com/season-stats/?seasonid=1920

    What I want to do is to to grab the 1920 number from the $seasonid variable and rework it in to the browser title, so that it will say something like “Lakers Season Stats 2019-20” or something similiar …and of course it changes based on that $season id variable. How would I pass that variable in the URL to the script, or could I grab a variable from inside the page itself and pass it to the script to the change the browser title? Either way, I just want to be able to change the browser title dynamically based on that. I also do have All In One SEO working as well.

    Thanks for any direction!

    • This topic was modified 3 years, 7 months ago by lakerstats.
    • This topic was modified 3 years, 7 months ago by lakerstats.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Since you’re using AIOSEO, you can use this filter to change the title dynamically – https://semperplugins.com/documentation/aioseop_title/

    Moderator bcworkz

    (@bcworkz)

    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.

    Thread Starter lakerstats

    (@lakerstats)

    Awesome thanks guys this gives me a great place to start!!

    Thread Starter lakerstats

    (@lakerstats)

    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.
    Thread Starter lakerstats

    (@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 = "&nbsp;$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;
    
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Changing Browser Title Based on Variable – WP 4.0’ is closed to new replies.