WordPress: display an "online since" message on your site

WordPress: display an "online since" message on your site

How to display the birthday date of your WordPress site.

If your WordPress site has been online for some years now, it would be surely useful to your visitors to know the birthday of your website. This can be easily achieved by getting the timestamp of your very first post.

You should simply get the ID of your first post on the WordPress backend and then insert the following function into your functions.php file:


function my_online_since() {
	$id = 2; // First post's ID
	$post = get_post($id);
	$ts = strtotime($post->post_date);
	$since = strftime('%Y/%m/%d', $ts);
	$html = '<p>Online since ' . $since . '</p>' . "\n";
	return $html;

}

Then you can display the function's output in your theme:


<header role="banner">
	<?php echo my_online_since(); ?>
</header>

The get_post() function returns an instance of the $post object. This function needs the post's ID to be passed as a variable.