I would like to write a PHP snippet that can communicate with Wordpress.

When a new post is published, a file today.jpg will be generated from the thumbnail url (a custom field) of the most recent post.

Or I can schedule a cronjob to execute daily for this action.

How can I implement this function?

My idea is to do it outside of functions.php so that it won't get executed all the time, while a scheduled update for today.jpg seems more resource friendly.

Any pointer is appreciated.


No need for a routine here - use the WordPress hook system to "attach" a function that will run when a post is published:

// https://codex.wordpress.org/Plugin_API/Action_Reference/publish_post

function wpse_225371_post_published( $post_id, $post ) {
   // Do your thang

add_action( 'post_published', 'wpse_225371_post_published', 10, 2 );
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.