php - Wordpress shortcode to display post date +1 day

14

I'm trying to create a shortcode that will display the post date +1 day. Example: if the post was published on the 3rd I want a shortcode that will display 4th. I've tried the following but not getting the results I want.

// [nextday]  
function displaydate_next(){  
    return the_time('jS', strtotime('+1 day')); 
}  
add_shortcode('nextday', 'displaydate_next'); 
// end nextday date
254

Answer

Solution:

I think you also need to get the month and year so it can calculate the next day. The below is what you need:

// [nextday]  
function displaydate_next(){  

$time = get_the_time('jS F, Y');
$date = strtotime(date("jS F, Y", strtotime($time)) . " +1 day");
return date('jS', $date); 

}  
add_shortcode('nextday', 'displaydate_next'); 
// end nextday date
96

Answer

Solution:

You can use WP Date and Time Shortcode for the purpose. Just adddays="+1" as an attribute.

For example:[wp-dt item="custom" format="jS" days="+1"].

People are also looking for solutions to the problem: Where should I put PHP code for a HTML form?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.