You can’t add an action to wp_head inside a wp-cron job. The wp-cron tasks run outside of the normal flow, so while you can add your action, it won’t actually do anything to anybody viewing the page. Cron jobs are called via separate http requests, no user normally will see their results.
In other words, your code works fine, it just doesn’t do what you’re expecting it to do. Although to be honest, I’m not entirely sure what you were expecting it to do. You certainly won’t see any change to the content of the page header, if that’s what you were thinking.
Related Posts:
- Should all plugins be encapsulated in a Class?
- Registering Class methods as hook callbacks
- Get plugin_dir_url() from one level deep within plugin
- How to use classes declared in another plugin?
- Namespaces in WordPress – How do I initiate the main class?
- How do I extend one plugin I’m writing with another I’m writing using classes?
- Adding an admin page – OOP approach not working
- Using the media uploader in a custom plugin
- Trying to get logged-in user data inside php class
- register child class in another plugin
- Check if a class exists within a method
- How to include and use custom class files in plugin?
- Creating a menu page in a Object Oriented developed plugin
- Current user in plugin returns NULL
- How to structure a plugin into multiple files using classes?
- Override WP Class Private Function
- Calling custom plugin class methods from a template
- Getting user roles in plugin files
- Plugin activation hook in an abstract class
- plugin class inheritance. cannot change variable
- Most efficient way to use classes to create admin pages using Settings API
- Basic Object Oriented plugin question
- Using plugin functions/methods within templates
- How to handle cookies from a WordPress plugin on a cached page?
- accessing parent variables in child construct without executing action in parent
- Object method calling for global $wpdb in header.php
- Why is my custom post type not being activated on plug-in activation?
- How to prevent PHP fatal error if plugin hasn’t been enabled and a method is called in theme file?
- get_option / wp_localize_script Not Working in OOP Plug In
- Built a second plugin but it overwrote the first one
- profile_update hook doesn’t works inside a class
- WordPress Object Oriented plugin development [closed]
- How to access OOP plugin function inside themes or other plugin
- Plugin: Hooking up classes that have their own hooks
- WordPress Custom Hook with Class method
- FPDF for creating pdf diplomas
- WordPress plugin blog creation
- Woocommerce functions in custom class, avoid errors
- Get post content inside plugin class method
- How to access classes in theme of a plugin?
- Reorganization of namespaces
- accessibility of an object created in a plugin, from the header
- Creating a register settings class that supports extended classes
- Autoloading a PHP class – working outside, but not inside WordPress plugin
- Why function hooked using object are executing at all time?
- How do add_action and WP_Query
- private functions in plugins
- Plugin won’t activate, fatal error (widget class not found)
- OOP Plugin: Where should I place the action hooks in the class?
- Global Handle to Class unavailable in Plugin?
- Strict Standards: Non-static method in sidebar generator
- Plugin: Custom menu item problem
- Function not being called on form submit, only blank admin-post.php page
- Disable plugins on cron and ajax page
- Convert WordPress pages to PDF
- Leverage browser caching not working after updating .htaccess
- How to attach Links into page/post or custom post type?
- How do I customize my WordPress shortlink structure in link-template.php without a plugin?
- A reliable AdSense plugin. Does it exist? [closed]
- wp_enqueue_style specifics for overwriting plugin styles
- How do I create a full-bleed background image on text mouseover? [closed]
- All plugins deactivated due to error
- WordPress Multisite – get_plugin_data()
- Error handling a plugin with exceptions
- Find unused images?
- Cannot install plugins on Centos VPS
- more types plugin – display all post of post type on page
- Plugin: WordPress Popular Posts > Possible to include custom post types?
- How can I copy all users to newly created site on a multisite network in WordPress?
- Remove /product/ from url. I want only category name then product name
- Regenerate thumnails does not create any files
- Does deleting a Plugin via the WordPress admin ‘completely’ remove the code?
- Merge tags in multistep Gravity Form?
- Woocommerce: limit user to see only the products he created
- How to get a list of all the available plugins names
- Plugin content is shown on every page
- Custom meta box with jQuery.sortable custom post type list
- Add a file upload field
- Is there anyway to rewrite woocommerce-template.php?
- Passing value as hidden parameter to next page
- Auto populate a user custom field from another user custom field
- How to Get Category Name When Export Products
- Create a form to get user information for payment gateway
- Custom plugin activation error
- Multiple image selection custom widget
- Execute inline javascript in wordpress after page fully loaded
- WordPress output data to another website and pull data
- How to execute certain code on back-end button press?
- How to add add blank non-editable wp page like default blog for use with plugin
- How do I override WordPress plugin css [closed]
- Creating Nested custom fields
- Home page letters
- Custom plugin breaks css.php on Multisite
- Retrieving old forms in Contact Form 7 [closed]
- Pulling Advanced Custom Fields from other pages
- Trying to use Advanced Custom Fields with custom image sizes
- Adding Category in URL in some post
- Fatal error in wordpress
- how to add meta for order in woocommerce
- Increased max_upload_filesize, but still can’t upload plugin [closed]