Archived topic
How do I manipulate the page titles?
5 replies · Started by Pete on April 19, 2016
How do I manipulate the header page titles? (the one in the browser tab, not the edit screen) I don't want to install any plugins to change it.
It's way easier to just use a plugin, but this might help: http://wordpress.stackexchange.com/questions/176940/add-theme-support-title-tag-in-conflict-with-custom-titles-function
Where about is the code that sets the titles? I'm asking as I really need to set some powerful conditionals as as my titles
or how could I edit this snippet so that I can free add some wp template tags
<?php add_action( ‘after_setup_theme’, ‘theme_functions’ );
function theme_functions() {
add_theme_support( ‘title-tag’ );
}
add_filter( ‘wp_title’, ‘custom_titles’, 10, 2 );
function custom_titles( $title, $sep ) {
//Check if custom titles are enabled from your option framework
if ( ot_get_option( ‘enable_custom_titles’ ) === ‘on’ ) { ?>
//Something like <?php if( is_sticky()) { ?>
// <?php } else { ?>
// <?php } ?>
$title = “Some other title” . $title;;
<?php }
return $title;
} ?>
This is already done in GP:
add_theme_support( 'title-tag' );
You're on the right track with the wp_title filter - you just need to use the right conditionals and then return the titles.
You might get some more in depth answers over on http://wordpress.stackexchange.com.
resolved