How to display/show current month and year in WordPress

User give preference to fresh updated content. Displaying latest and current month and year in your title

Content doesn’t change month by month so it can be cumbersome to change updated year or month in every post.

So I will be discussing how you can do that without any plugin.

You can edit your theme functions.php file if you don’t want to use plugin but if you update your theme then those changes will be reset and you will have to insert the code again.

Although I have said without any plugin

Step 1: Install Code Snippets Plugin (wp link)

Step 2: Choose the code and copy it.

This snippets will show month(full) and year. Example: February 2022

add_shortcode( 'date_year' , 'current_date_year' );
function current_date_year() {
    return date("Y");
}

add_shortcode( 'date_month' , 'current_date_month' );
function current_date_month() {
    return date("F");
}
add_filter( 'the_title', 'do_shortcode' );

If you want to display only initials of the month. Then copy this code

add_shortcode( 'date_year' , 'current_date_year' );
function current_date_year() {
    return date("Y");
}

add_shortcode( 'date_month' , 'current_date_month' );
function current_date_month() {
    return date("M");
}
add_filter( 'the_title', 'do_shortcode' );

In step I will show how you can show these

Step 3: Creating the snippet.

Firstly go to snippets and all snippets.

In the top choose Add New.

Paste the code

Conclusion

How to display current month and year in post title in WordPress

Leave a Comment

Share via
Copy link
Powered by Social Snap