Skip to content

Commit

Permalink
#378 copyright year shortcode (#379)
Browse files Browse the repository at this point in the history
* Added copyright year shortcode

* Added support for shortcodes within copyright text

* Defined current year variable.
  • Loading branch information
mharis authored and gregrickaby committed Sep 18, 2018
1 parent 527d34d commit 0a7bf25
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions inc/extras.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,33 @@ function _s_display_customizer_footer_scripts() {
// Otherwise, echo the scripts!
echo force_balance_tags( $scripts ); // WPCS XSS OK.
}


/**
* Shortcode to display copyright year.
*
* @author Haris Zulfiqar
* @param array $atts {.
* @type string $starting_year Optional. Define starting year to show starting year and current year e.g. 2015 - 2018.
* @type string $separator Optional. Separator between starting year and current year.
* }
* @return string
*/
function _s_copyright_year( $atts ) {

// Setup defaults.
$args = shortcode_atts( array(
'starting_year' => '',
'separator' => ' - ',
), $atts );

$current_year = date( 'Y' );

// Return current year if starting year is empty.
if ( ! $args['starting_year'] ) {
return $current_year;
}

return esc_html( $args['starting_year'] . $args['separator'] . $current_year );
}
add_shortcode( '_s_copyright_year', '_s_copyright_year', 15 );
2 changes: 1 addition & 1 deletion inc/template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ function _s_display_copyright_text() {
}

?>
<span class="copyright-text"><?php echo wp_kses_post( $copyright_text ); ?></span>
<span class="copyright-text"><?php echo wp_kses_post( do_shortcode( $copyright_text ) ); ?></span>
<?php
}

Expand Down

0 comments on commit 0a7bf25

Please sign in to comment.