I always find working through a specific example helps me understand – so I’d like to see how to convert code into a function I can call over and over.
This code reads a date from a custom field in wordpress called ‘date’ in the format YYYYMMDD and shows it as a full length friendly date (eg ‘Monday 1st January 2001’). I’s like to move it as a function in function.php file so I can call it from different places, and understand how that conversion happened.
<?php
$date = get_post_meta($post->ID, 'date', true);
if ($date){
$mydate = "$date";
echo date('l, j F, Y', strtotime($mydate));
}
?>
Thanks!
Then call it by doing:
You might want to validate it 1st so you make sure it does not return
false