If you need it on the first day of the month, you should still run this daily. Just be sure to check if “today” is the first of the month. Even your “first day of the year” would be executed if it is the first day of the month.
You can check this with the following:
$dtFirst = new DateTime('first day of this month');
$dtToday = new DateTime('today');
$interval = $dtToday->diff($dtFirst);
// format('%a') produces total 'days' from DateTime::diff()
if ($interval->format('%a') == '0'){
// Do your stuff here...
}
Doing this check daily will avoid issues with leap years, etc., without significant impact to your server.
I would also recommend you use a system cron to replace the WP Cron, to ensure you get a proper execution. WP Cron is too dependant on user activity.
Related Posts:
- Does wp-cron runs all tasks scheduled at same time together or one after other?
- How wp-cron can run in background if PHP is single threaded?
- Running WP Cron on multisite the right way
- Initialize WordPress environment to use in a real cron script
- Multiple wp_schedule_event cron jobs in plugin cause multi-execution
- How to use a frontend URL with a Plugin
- How to display a value from a radio button in the options menu in wordpress
- export a csv file from the database with a cronjob
- WP CRON duplicate wp_insert_post with has < and > tag
- WP Cron job timeout issues
- running wp-cron.php using php not wget
- Scheduling an event inside plugin class is not working
- Large WordPress CRON job
- Switch from wp-cron to a server cron job
- WordPress cron is running with previously set time intervals and not the updated one
- Can/should we delete wordpress cron jobs with no action?
- Setting up a cron job to auto update a custom field
- Drop down question
- How do I disable cache for a certain page?
- Problem with my Login Plugin
- How to return html as a string from php for WordPress
- post_exists stops working in a scheduled event
- CRON job to update wp_usermeta value each day or week based on server time
- Cron not sending wp-mail()
- Php cron job (wp-cron) not working
- How to execute add_action() function from custom plugin to Crontrol plugin or do_action()?
- start_lvl Ignored in Custom walker_nav_menu
- What exactly does “Posts page” do in WordPress?
- What would be a PHP command to erase all posts from category X from the last month?
- Adding a search form inside a div
- Load custom field value into div with AJAX
- Blank on static home page?
- WordPress template_include filter not working properly
- Custom image upload
- How to display recent posts on home page with custom HTML
- WordPress automatically adds tags when pasting code, how to stop it?
- Slide in Panel WordPress Post
- Upload Image in a WordPress page using PHP
- How to trigger $_GET request within admin plugin page?
- WP add_action factory
- Swapping wp_dropdown_categories function with wp_category_checklist
- How to show phpinfo() only in a new tab?
- My form action url is being prepended with a directory that does not exists
- custom fields wordpress
- Why the JavaScript code is ignored from wp editor?
- Populate dropdown with Child Pages based on Parent Page chosen
- How can I remove a function that has been added to wordpress with add_filter?
- Why Won’t My Inputs in a form with a Get method work together?
- Extend PHP regex to cover “srcset” and “style” attributes
- How to get the value of input hidden html from text editor to custom page template?
- How can I hide that I Use WordPress (with W3 Total Cache)
- Saving plugin settings – ERROR: options page not found
- class_exists returns different values [closed]
- How to convert select to HTML with PHP tags inside of it [closed]
- Custom array from a query only write the last row of the query
- Add Codepen animation as Preloader to WordPress
- Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
- php esc_html_e with an html link inside not working
- Using ob_start and ob_get_clean with wordpress shortcode
- Custom meta box values are not getting saved for my custom post type
- WordPress wp-admin redirect and exception
- Set default Database Storage Engine when creating tables with plugins?
- Is it possible to isolate and use WordPress functions outside of wordpress
- Ajax on the Administration Side of plugin – wp_localize_script – how to pass value from JQuery to PHP function in class?
- WordPress can’t use ZipArchive
- How to change basename url for wp-admin?
- Search bar for wp menu
- Executing php on button press
- Only the first image uploads
- WordPress loading progess – wp-blog-header.php
- Illegal string offset checkbox
- Trying to use a variable to set image width
- WP Website is shown in HTML
- wp_update_post gives 500 internal error
- How to translate to spanish wordpress hardcoded content/files?
- Mysterious letters appearing at the top of a few pages
- Current WordPress Page Title as Search Parameter into A Tag
- If user has clicked link add class and store using PHP/WordPress
- register_setting not save checkbox
- How to Protect a private folder inside uploads folder, if User is not Logged In?
- How does one make a URL return dynamic JSON with custom Content Type?
- How to give custom roles the capability to edit one Menu instead of every Menu
- sessionStorage saves input value in browser but it is not loaded in the form field
- Changable favicon
- New database entry to trigger runing PHP/SQL query through link with token, without logging into the website
- defined (‘ABSPATH’) false after AJAX post to other PHP-file
- Multisite – Display different header content based on which site is accessed
- html to posts, jpg to featured image, zip file contains jpg and html
- How do you change the tag font size in the repeater-template.php [closed]
- PHP tag in post content makes wordpress go crazy
- WordPress Cron function is not working
- Private messaging – Getting and displaying the avatar/url of a message recipient
- widget: input the px value from user and use it as inline style in widget function
- RegExp to EXCLUDE strip HTML (FOR SOMME) comments
- Pagination for div’s
- How Can I Center the Logo in the Navigation Menu? [closed]
- Adding custom cron_schedule prior to wp_schedule_event
- SHARING TO FACEBOOK – FROM DYNAMICALLY GENERATED PAGE
- ‘This Field is Required.’ is Not Displaying on CF7 [closed]
- How to modify default tags in wp_head()