1

I'm a total newbie at PHP/WordPress, so please help me out: I want to add the current calender week (the week number in the year) to my webpage. My idea was to first create a new shortcode in the functions.php file:

function current_week_shortcode() {
    return date('W');
}
add_shortcode('current_week', 'current_week_shortcode');

Then I added [current_week] as a new shortcode block to my page. However this doesn't work. Instead it just shows the line, as if its normal text. What did I do wrong? It seems as if WordPress doesn't even recognize it as a short code and therefore doesn't execute it. Did I add the code at the wrong place in the functions.php file? I added it at the end, right above </style> <?php }

Thanks in advance for every advice!

2
  • 3
    "I added it at the end, right above </style> <?php }" - not sure why you would have a <style> element in your functions.php to begin with (someone is doing something really dirty there), but the code to add the shortcode of course needs to go inside of <?php ... ?> tags, not outside. Commented Apr 16, 2024 at 9:38
  • Your code looks correct. Is it possible that a theme is overriding the functions.php script, or you need to put the function in a child theme instead? Do you have any other custom functions infunctions.php script that work? Commented Apr 20, 2024 at 23:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.