Javascript,Nodejs,MongodDB,WordPress,CSS,PHP

LightBlog

Wednesday, August 15, 2018

How to create a short code in wordpress

Copy and paste it in functions.php file

<?php function  date_year_shortcode()
{
 $year = date('Y'); return $year;
 }

add_shortcode('year', 'date_year_shortcode');
?>

display the year : [year]

if you want to use it on template , then use wordpress inbuilt function do_shortcode

<?php echo do_shortcode('[year]'); ?>

No comments:

Post a Comment