Strip and print only the numbers found in current’s post excerpt (even if they are without space)

If you have a strict list of allowed years: $allowed_years = array(‘2018’, ‘2019’, ‘2020’, ‘2021’, ‘2022’, ‘2023’, ‘2024’); Then why are you using regex when you can search for those years directly: function vyperlook_get_years_in_text( string $text, array $allowed_years ) : array { $found_years = []; // the years we found // for each year that … Read more

How to use webpack in WordPress theme? I want some scripts to load in the footer, some in the header and some with script parameters

What is the right and clean way to load these files in WordPress? The same way as you’ve always done it, wp_enqueue_script. WordPress is unaware that webpack created the javascript file, and it is just that, a javascript file. This is true wether it contains jquery, was written by hand, or was created by a … Read more

Function attached to cron job not running but will run if called manually

It looks like the time() was not set correctly in the first iteration of the function wp_schedule_event; First, remove this task from the queue by adding a function wp_clear_scheduled_hook and reload the page. For your example: wp_clear_scheduled_hook( ‘opportunities_cron_job’ ); Remove the cleaning function. Restart your code. If your date is not set correctly again, use … Read more

Execute wp_after_insert_post after the permalink is customized

To execute update_post_meta after the permalink is customized, you can use the save_post hook instead of wp_after_insert_post. Here’s how you can modify your code: add_action(‘save_post’, ‘add_permalink_to_new_post’, 10, 2); function add_permalink_to_new_post($post_id, $post) { // Check if this is a new post if ($post->post_date_gmt == $post->post_modified_gmt) { // Only run this on a newly created post update_post_meta($post_id, … Read more