Change title in browser tab

user2651058 picture user2651058 · Aug 6, 2013 · Viewed 8.2k times · Source

I'm trying to change the title in browser tab for a child theme of twentytwelve. I wan't it to print out the same title on every page. What the heck is happening?

    <?php
    function im_awesome_title($title){
      $title = "Im awesome!";
    return $title;
    }
    add_filter( 'wp_title', 'im_awesome_title', 20 );

Answer

Oleg D picture Oleg D · Dec 5, 2019

or some like this. script better put in the end of all php tags

<?php
//set title
echo "<script>setTimeout(function(){var tts = document.getElementsByTagName(\"title\");if(tts.length > 0)tts[0].innerHTML=\"My title\"; else {var tt0 = document.createElement(\"TITLE\"); tt0.innerHTML = \"My title\"; document.head.appendChild(tt0);}}, 200);</script>";
?>