Last active
March 26, 2019 15:55
-
-
Save itzmekhokan/582fa15b5fc9ad398ee9d6cee93e4766 to your computer and use it in GitHub Desktop.
Automatically Add Dynamic Title to Pages in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* 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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment