Auto insert month/year in title > Jul 2020

Categories: Wordpress, CMS

Add this to functions.php:

/* Activate shortcode function in Post Title */
add_filter( 'the_title', 'do_shortcode' );

/* Activate shortcode function in Yoast Title and Meta Description */
add_filter( 'wpseo_title', 'do_shortcode' );
add_filter( 'wpseo_metadesc', 'do_shortcode' );


/* Shortcode to display the current month and year in WordPress */
/* shortcode: Jul 2020 */
add_shortcode( 'month_year' , 'current_month_year' );
function current_month_year() {
     $year = date("Y");
     $month = date("M");
     return "$month $year";
}

/* Shortcode to display the current year in WordPress */
/* shortcode: 2020 */
add_shortcode( 'year' , 'current_year' );
    function current_year() {
    $year = date("Y");
    return "$year";
}

Works with Yoast SEO plugin.

/* Shortcode to display the current month and year in WordPress */
/* shortcode: [long_month_year] */
add_shortcode( 'long_month_year' , 'current_long_month_year' );
function current_long_month_year() {
     $year = date("Y");
     $month = date("F");
     return "$month, $year";
}

Reference:

https://www.blackhatworld.com/seo/method-boost-clicks-from-google-by-auto-inserting-month-year-in-title.1223548/

«
»