Change title tag dynamically or within plugin?

As of WP 4.4, wp_title is deprecated. If you simply need to override your title tag, pre_get_document_title is the filter you want to use.

add_filter( 'pre_get_document_title', 'generate_custom_title', 10 );

and the function would look something like this

function generate_custom_title($title) {
/* your code to generate the new title and assign the $title var to it... */
return $title;  
}

If you’re a stickler you’ll know that pre_get_document_title doesn’t normally take any args; but if you use the Yoast SEO plugin, you’ll find out that this function doesn’t do anything! So I also hook the ‘wpseo_title’ filter onto this same function.

add_filter( 'wpseo_title', 'generate_custom_title'), 15 );

just in case Yoast is turned on. Code reuse.