Custom WordPress shortcode functions

Here is an example of creating shortcode for your wordpress blog,   this is a simple use of shortcodes and you can write much more complex shortcodes when required.
</pre>
//[yearsExperience]
 function yearsExperienceFunction()
 {
 $date1=new DateTime("now") ;
 $date2=new DateTime("1990-1-1");
 $date= $date1->diff($date2);
 return $date->format('%y');
 }
 add_shortcode( 'yearsExperience', 'yearsExperienceFunction' );

This shortcode writes out the number of years since a given date, this function can be added to your funcitons.php file and its hook add_shortcode registers the function for use, you can then call the function from within your post.

[yearsExperience]

For more information on shortcodes please visit http://codex.wordpress.org/Shortcode_API

One thought on “Custom WordPress shortcode functions

  1. Hey very cool site!! Man .. Beautiful .. Wonderful .. I will bookmark your website and take the feeds also?I am satisfied to find numerous helpful info right here within the put up, we want develop extra techniques on this regard, thank you for sharing. . . . . .

Leave a Reply to versicherung Cancel reply

Your email address will not be published. Required fields are marked *