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
- Is it possible to use Classes between WordPress plugins with separate namespaces?
- Load plugin on specific page only
- Does a plugin’s “main” file need to be named the same as the folder containing it?
- Overwrite textdomain of plugins by default – Lost Translation
- Google Analytics post views in WordPress? [closed]
- WP Config for FTP credentials
- Multi step form, custom plugin
- Contact Form 7 plugin refreshing page on submit [closed]
- Some Plugin Settings Are Kept After Removal and Reinstall of the Plugin
- why does the add_action(‘the_content’) overwrite my page
- Is it ok to call get_option without hooks?
- Can I check plugins and themes for PHP 5.6 ahead of global PHP server Update
- How can I reuse the WordPress search form for a custom plugin / widget?
- Where should a plugin or widget cache its results?
- Set of plugins to control the Admin UI
- How to transfer all user data between wordpress installations?
- Plugin upgrade issue
- __callStatic method handler passed to add_action causes bug in PHP
- Multiple instances of nivo slider plugin
- Interactive filters on wordpress [closed]
- Add padding while generating thumbnail
- flush_rewrite_rules() not working with update_option_{$option}
- Price comparison table based on Custom Post Type?
- How do I determine if the user who registered is not spam?
- How to get a custom page through plugin?
- Filters on the_content with plugins, pages and shortcode
- Plugin to send messages to members/lists but not full-blown newsletters
- can’t install any wp plugins [duplicate]
- Add Plugin broken after removing Booster for Woocommerce
- WP_CONTENT_DIR disables plugin directory
- Undefined index: custom_post_template_present
- Ensure WordPress Theme Uninstalls Completely
- Warning: sprintf(): Too few arguments in nav-menu-template.php
- Coupon Codes for product discount combined with conditional free shipping
- How to fix slow comment query?
- wp meta_query meta_value compare =REGEXP delimited by space
- Sending post data over REST API, how to parse shortcodes in post_content?
- Primary Menu doesn’t show because of w3 cache
- Wp Ecommerce Reposition Product Page Product Thumbnail Image
- Array to string conversion error when trying to POST multidimensional array
- How to test a WordPress plugin on a single post?
- How to Overwrite validate_plugin function
- Plugin and javascript placement
- Disable plugin function
- Form data to wordpress DB
- How to validate password length in wordpress
- URL Redirect on GoDaddy platform [closed]