[Resolved] How to add current year into a blog title?

Home Forums Support [Resolved] How to add current year into a blog title?

Home Forums Support How to add current year into a blog title?

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1989565
    Wendy

    Hello, I have a couple of articles that I insert the current date manually.

    It’s an annual admin task that I’m sure could be avoided through simple code??? But what??

    Here is an example:

    https://www.glow-skincare.com/argan-oil-vs-jojoba-oil/

    Thank you 🙂

    #1990007
    David
    Staff
    Customer Support

    Hi there,

    so are you updating the date only on specific posts ?
    Problem with doing it with code, is knowing which posts that change should be applied to and when….

    let me know

    #1990837
    Wendy

    Yes only on a handful of posts, so I would know their page ID?
    25979
    3585
    21978
    23857
    24910
    25486
    25672
    4751

    #1990863
    David
    Staff
    Customer Support

    You could use a Shortcode to display the Year in the title – this article explains one method:

    https://technumero.com/auto-add-dynamic-year-in-wordpress-post-titles/

    Note – that it includes the filter for do_shortcode in the_title, as well as some filters specifically for Yoast – THIS is important to note if you’re using any SEO plugins or Feeds those too would require filtering.

    Unfortunately something that seems very simple has several pitfalls….

    #1990894
    Wendy

    Ooh yes, that’s perfect now thankyou David. (also for the heads up on SEO plugins or Feeds..)

    #1990911
    David
    Staff
    Customer Support

    You’re welcome!

    #2153667
    Wendy

    Hello David, hope you are well!

    I switched from Yoast to SEOPress on the weekend, and now in MonsterInsights I am seeing strange stuff:

    instead of :Bach Flower Remedies List – 2022 Guide

    they appear as Bach Flower Remedies List – [year] Guide

    The current snippets refer to Yoast: – do I simply change Yoast to SEOPress?

    Thank you so much. Current Snippet code pasted below.

    //* Shortcode to display the current year in WordPress
    //* shortcode: [year]
    add_shortcode( ‘year’ , ‘current_year’ );
    function current_year() {
    $year = date(“Y”);
    return “$year”;
    }

    add_filter( ‘the_title’, ‘do_shortcode’ );//* Activate shortcode function in Post Title
    add_filter( ‘wpseo_title’, ‘do_shortcode’ );//* Activate shortcode function in Yoast Title
    add_filter( ‘wpseo_metadesc’, ‘do_shortcode’ );//* Activate shortcode function in Yoast Meta Description

    #2153898
    David
    Staff
    Customer Support

    So this:

    //* Shortcode to display the current year in WordPress
    //* shortcode: [year]
    add_shortcode( 'year' , 'current_year' );
        function current_year() {
        $year = date("Y");
        return "$year";
    }
    
    //* Activate shortcode function in Post Title
    add_filter( 'the_title', 'do_shortcode' );

    Is the only code that will work anywhere regardless of what SEO plugin you’re using.

    The other two add_filters are 100% yoast specfic ie. wpseo_title and wpseo_metadesc.
    You would need to ask SEO Press if they have their own filters for their SEO title and SEO descriptions.
    You can share this topic with them so they can see what you need them for.

    #2154512
    Wendy

    Thank you David!

    I have now switched back to Yoast…it seems better geared up.

    #2154521
    David
    Staff
    Customer Support

    You’re welcome

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.