Skip to content

Instantly share code, notes, and snippets.

@itsViney
itsViney / functions.php
Last active March 26, 2022 20:44
Wordpress shortcode that returns the current year. For footer copyrights, mostly.
/* Basic shortcode to return the current year (for copyright line)
Example: © [year] itsViney
*/
function currentYear($atts)
{
return date('Y');
}
add_shortcode('year', 'currentYear');
@itsViney
itsViney / functions.php
Last active March 26, 2022 20:49
Wordpress shortcode based on Advanced Custom Fields' standard shortcode that adds the ability to specify which part of a 'link' field to return. Options for 'element' are url, title or target.
/* Enhanced ACF link shortcode. Return format must be array for this to work
Element can be url, title or target
Example: [acf_link field="my_link_field" post_id="1000" element="url"] (returns the URL of the link)
Example: [acf_link field="my_link_field" post_id="1000" element="title"] (returns the title of the link)
*/
function acf_link_shortcode($atts)
{
extract(shortcode_atts(array(
'field' => '',
@itsViney
itsViney / functions.php
Last active March 26, 2022 20:46
Wordpress shortcode based on Advanced Custom Fields' standard shortcode that adds the ability to specify a format for date fields.
/* Enhanced ACF date shortcode. Return format must be set to Ymd in ACF for this to work
Example: [acf_date field="my_date_field" post_id="1000" date_format="d F Y"]
*/
function acf_date_shortcode($atts)
{
extract(shortcode_atts(array(
'field' => '',
'post_id' => false,
'format_value' => true,
'date_format' => ''