Issue with ShortCode

#23527
  • Resolved Nirav Dave
    Rank Math free

    I am having a strange issue.

    I normally use a tag [year] in my post title to add the current year.

    For this, I am using the following code in my function.php file on WordPress,

    function year_shortcode() {
      $year = date('Y');
      return $year;
    }
    add_shortcode('year', 'year_shortcode');

    Rank Math plugin is not recognizing the code and is displaying [year] in my meta titles on Google.

    Help appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Nirav Dave
    Rank Math free

    Hi guys,

    Any help appreciated.

    Michael Davis
    Rank Math pro

    Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    Could you please try the following code on your theme’s functions.php file:

    /**
     * Filter to change the page title.
     * 
     * @param string $title
     */
    add_filter( 'rank_math/frontend/title', function( $title ) {
            $title = do_shortcode($title);
    	return $title;
    });

    Looking forward to helping you. Thank you.

    ​​​​​​​

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)

The ticket ‘Issue with ShortCode’ is closed to new replies.