You can use any of these characters (below) for formatting your date. So, to include the month, you would replace date('Y'); with date('F Y'); or date('M Y');, depending on whether you want the full textual representation of a month or just the first three letters. http://php.net/manual/en/function.date.php
Thanks, works really nice! But the shortcode displays the month in English even though I set the site language to Swedish under Settings > General. Is there anyway to change that? I’ve used the following code:
Hey Victor! Yeah, you should be able to tweak the format by fussing with the Y variable. Here’s a list of all the available formatting options that are offered: https://codex.wordpress.org/Formatting_Date_and_Time
Bless your cotton socks. I’d previously been using a javascript code that was slowing down the current site I’m working on (wblc.com.au) by about 3 seconds. This was cleaner and has sped up the site. Thank you!
Thanks! That code works great!!!
Nice, works like a charm. Thanks for sharing this useful tip.
Copyright © $starty){echo $starty.’-‘.$nowy;}else{echo $nowy;} }else{ echo date(“Y”);} ?> . All Rights Reserved.
Copyright © <?php date_default_timezone_set(PRC); $starty=get_option(‘cwpcg_starty’);
$nowy=date(“Y”); if(get_option(‘cwpcg_starty’)){ if($nowy>$starty){echo $starty.’-‘.$nowy;}else{echo $nowy;} }else{ echo date(“Y”);} ? > <?php bloginfo(‘name’); ? >. All Rights Reserved.
Great! Just what I needed for multisite footer info.
Awesome! Just what I was looking for.
If you want to include shortcodes in your widgets, such as
[year]
in a footer widget for the copyright date, then add this to your functions.php file:Just the extra bit I needed. Thanks, Paul!
How could you add the month before the year so that the shortcode returned Month Year?
That would be rad and I’m stumped.
You can use any of these characters (below) for formatting your date. So, to include the month, you would replace
date('Y');
withdate('F Y');
ordate('M Y');
, depending on whether you want the full textual representation of a month or just the first three letters.http://php.net/manual/en/function.date.php
Got it. That worked great. I wasn’t sure about the syntax and that manual helped for sure. Appreciate it!
How can I add a shortcode to an Advanced Custom Field?
It might depend on the type of ACF field, but converting the “Convert tags to HTML” option looks like it would work based on this thread from the ACF forum: https://support.advancedcustomfields.com/forums/topic/how-to-output-a-shortcode-in-an-input-field/
For year range, you could use :
Thanks, works really nice! But the shortcode displays the month in English even though I set the site language to Swedish under Settings > General. Is there anyway to change that? I’ve used the following code:
function year_shortcode() { $year = date(‘F Y’); return $year; } add_shortcode(‘year’, ‘year_shortcode’);
Hey Victor! Yeah, you should be able to tweak the format by fussing with the
Y
variable. Here’s a list of all the available formatting options that are offered: https://codex.wordpress.org/Formatting_Date_and_TimeBless your cotton socks. I’d previously been using a javascript code that was slowing down the current site I’m working on (wblc.com.au) by about 3 seconds. This was cleaner and has sped up the site. Thank you!
function year_shortcode()
{
ob_start();
echo date(‘Y’);
return ob_get_clean();
}
add_shortcode(‘year’, ‘year_shortcode’);