Displaying My Age in WordPress

Displaying My Age in WordPress , so here is what seemed like a simple thing to achieve .The obvious is just to insert my current age and update it each year. Not a great solution as I’m bound to forget to do it and also which articles that my age exists on.
I wanted to display my age anywhere posts, pages or widgets which is dynamically updated each year I feel a shortcode coming on.

So off to the WordPress Plugin Repository to check out what if any plugins would help me achieve this. Now there were a couple that would enable this but the ones I looked at were either overly complicated or had not been updated for some time so no luck there.

Next stop was a google search this was far more fruitful and took me off to a couple of articles that helped me solve the problem.

<?php // DISPLAY YOUR AGE // function whats_my_age_again($  birthday) {     extract( shortcode_atts( array(         'birthday' => 'birthday'     ), $  birthday));     return date("Y", time() - strtotime($  birthday)) - 1970; } add_shortcode('show-my-age', 'whats_my_age_again'); ?>

So now I just use this shortcode to display my age anywhere simple.

I am [show-my-age birthday="11/18/1959"] years old.

This gem of a shortcode was discovered here https://www.doitwithwp.com/

Interestingly in my search for a solution I came across an article which explores

how to set up a child theme and a functionality plugin for your site, so that you can make changes to your site in the correct manner, without putting your edits, or the rest of your site at risk.

This article is well worth a read as it really does explain some really robust methods to developing your WordPress site.

The post Displaying My Age in WordPress Dynamically Display Current Age appeared first on WPCommunity.

WPCommunity

Tags: , , , ,