How to Modify Title Tag in WordPress

I always missed a function to directly change the title tag in WordPress template. But here is a function which can do that for you.

function modify_title( $new_title ) {
    add_action( 'pre_get_document_title', function( $current_title ) use( $new_title ) {
        return $new_title;
    }, 9999 );

Please note that this function uses use keyword to bind variables into anonymous function’s scope. Learn more

By Abhineet Mittal

Abhineet is IIM Alumnus and Founder of popular Digital Publishing Platform, Sahityapedia. He is a technology enthusiast by hobby & an avid reader.