WordPress : Modify Title post with a dynamic tag for better SEO experience

Let us say that you want to display events every month with changing title post for your calendar to current month (see http://www.salsarock.com/agenda/soirees)

In wp-include/general-template.php Modify your function _wp_render_title_tag to display the calculated dynamic string to add in your title page or post.

/**
 * Displays title tag with content.
 *
 * @ignore
 * @since 4.1.0
 * @since 4.4.0 Improved title output replaced `wp_title()`.
 * @access private
 */
function _wp_render_title_tag() {
	if ( ! current_theme_supports( 'title-tag' ) ) {
		return;
	}
 global $post;
	//$year = date("Y");
	//$month = date("F");
	$madate = date_i18n("F Y");
	$str = 'Soirées Salsa à Paris en ' . $madate;
	$postid = get_the_ID();
	
	if ( $postid == 121 ) {
	    echo '<title>' . $str . '</title>' . "\n";
		
	}
	else {
  echo '<title>' . wp_get_document_title()  . '</title>' . "\n";
   }
}

In the functions.php of your theme add those functions to change the tag salsadanse to show the current month :

 //* Activate shortcode function in Post Title

add_filter( 'the_title', 'do_shortcode' );



add_shortcode( 'salsadanse' , 'current_year' );
    

function current_year() {
	
	$salsadanse = date_i18n("F Y");
    return "$salsadanse";
}   

extradrmtech

Since 20 years I work on Database Architecture and data migration protocols. I am also a consultant in Web content management solutions. I am an experienced web-developer with over 10 years developing PHP/MySQL, C#, VB.Net applications ranging from simple web sites to extensive web-based business applications. When not writing code, I like to dance salsa and swing and have fun with my little family.

You may also like...