WordPress Function to Automatically Add Dynamic Titles to Public Pages

Automatically Add Dynamic Titles to Public Pages

Tested on: WordPress 3.0.1

Utilizing the code below will automatically create dynamic page titles based upon the pages/posts being viewed publicly.

/* Dynamic Titles **/
// This sets your <title> depending on what page you're on, for better formatting and for SEO
// You need to set the variable $longd to some custom text at the beginning of the function
function dynamictitles() {
$longd = __('Enter your longdescription here.', 'texdomainstring');
    if ( is_single() ) {
      wp_title('');
      echo ' | '.get_bloginfo('name');

} else if ( is_page() || is_paged() ) {
      bloginfo('name');
      wp_title('|');

} else if ( is_author() ) {
      bloginfo('name');
      wp_title(' | '.__('Author', 'texdomainstring'));

} else if ( is_category() ) {
      bloginfo('name');
      wp_title(' | '.__('Archive for', 'texdomainstring'));

} else if ( is_tag() ) {
      echo get_bloginfo('name').' | '.__('Tag archive for', 'texdomainstring');
      wp_title('');

} else if ( is_archive() ) {
      echo get_bloginfo('name').' | '.__('Archive for', 'texdomainstring');
      wp_title('');

} else if ( is_search() ) {
      echo get_bloginfo('name').' | '.__('Search Results', 'texdomainstring');
} else if ( is_404() ) {
      echo get_bloginfo('name').' | '.__('404 Error (Page Not Found)', 'texdomainstring');

} else if ( is_home() ) {
      echo get_bloginfo('name').' | '.get_bloginfo('description');

} else {
      echo get_bloginfo('name').' | '.($blog_longd);
}
}

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *