Reputation: 7094
I have a function to display the date of an article:
get_the_date('M j, Y');
This will return the date in a string:
Apr 10, 2015
I want to hide the year if it is the current year. What would be the best way to do this?
Upvotes: 1
Views: 181
Reputation: 1333
$date_str=get_the_date('M j, Y');
$parts= explode(",",date_str );
// some validation
if ($parts[1]==date("Y")) //then same year
{
$date_str = $parts[0]; //just the month
}
//your string in $date_str...
Upvotes: 2
Reputation: 5792
As we don't know what's there in your get_the_date
function. This might help you.
if(date('Y')==get_the_date('Y')){
get_the_date('M j');
}
else{
get_the_date('M j, Y');
}
Upvotes: 1