You’re adding the action on comment_form_before_fields
in comment_form_logged_in_after
. The latter is called only when the user is logged in, and the former is only called when the user is not logged in.
You can add WordPress actions and filters at any time after WordPress is initialized. If you’re adding the action in a plugin, add it on init
or even when the code is first executed (i.e. not on an action but directly in the plugin).
This way, the action is added immediately and called when it needs to be called.
Related Posts:
- Comment search plugin
- How can I edit comment meta value before it is saved?
- Trouble understanding apply_filters()
- How many filter/action hooks are healthy?
- Earliest hook to reliably get $post/$posts
- What does (10, 2) mean when used with add_filter
- Valid characters for actions, hooks and filters
- How to check if a hook is hooked or not?
- How to make post and comment count unclickable with dashboard_glance_items hook
- Hook into admin post list page
- Anyway to edit the titlebar of WordPress Widgets in the Admin area?
- About Hooks and Filters
- How to enable visual editor when editing comments on the dashboard?
- Should I use add_action(‘publish_post or add_filter(‘publish_post?
- Please explain me what the do_action does
- An action hook where a comment meta is updated
- Too many actions/filters!
- How to get list of all hooks of current theme / plugin?
- How does WordPress call functions attached to a certain action hook before calling functions attached to other hooks
- Conditionally call add_action depending on post_type?
- Why anything done on comments_array hook gets reset?
- Is it possible to track down Actions and Filters?
- When to use actions and when to use filters
- Is possible dequeue/remove style from wp_footer() hook and add on wp_head() hook?
- Same Conditionals Not Working on Two Different Hooks
- How to call a function or method that is Namespaced using another plugin
- add filter login_redirect does not contain original requested redirect
- get_header and hook avoid normal call
- Can the wp_filter object hold multiple values with the same key
- How to change the order (priority) of registered filters (or actions) (e.g. for the_content)?
- apply_filters/do_action tag characters limit
- Filter taxonomy admin pagination
- Insert term when page is published – avoid duplicates after edits
- How to modify core when there is no hook?
- Capture post content before page renders
- How to remove action with slashes and arrows?
- Changing WordPress core without hacking core
- How can I output all apply_filters and do_action?
- How to allow code block in wordpress comments
- Remove actions/filters that are set with create_function()
- Get The Caller (Plugin / Theme / Core) For All actions & Hook in WordPress
- Remove tags without a specific meta key from “choose from the most used tags”
- How to access page variable inside action hook
- What is the action hook to use if you want to capture the new password during password change?
- Action hook to control access to certain parts of my site
- How do I add tags to entire comments, not just their text
- Replace Data In Post & Update Meta Field Post Is Saved
- style_loader_tag not changing stylesheet to preload
- How can I filter the comment action links so that I can display the actions links based on user capabilities?
- Hook to change the site URL
- Hook to add content after date in post?
- Hook inside a hook
- Converting restricted html in comments to bbcode
- Can you call a filter hook by “add_action”?
- Adding link options in insert/edit link dialog window
- How to redirect a unique link based on login status
- Save_post – Warning: Cannot modify header information
- Modify WordPress Page Title ()
- Add an attribute to the root from functions.php with add_filter
- Would like to use hook or filters to customize email templates
- How Do I Unhook This Parent Theme Function?
- Is it possible to assign a css id to a row in plugins list table?
- Right filter for rewriting page statuscode
- Add filter return false not working
- add_action with associative array
- Use action, filter, or hook to append HTML to WordPress plugin function
- how to use apply filter for Class?
- How can I see exactly what arguments are being passed through a filter so that I may modify them?
- WordPress set featured image to first image of the post
- Add Index to Item in WordPress Gallery
- Remove image of srcset
- WordPress Plugin Boilerplate – add actions and/or filters based on user’s role
- Re-order search results with posts_orderby filter and post meta value
- Security question – Display a General Custom Login Error Message
- Does anybody know what the $current_screen ->id for customizer.php is?
- adding an action inside if condition not working
- Using add_filters() , apply_filter(), add_action() and do_action() in extending a plugin
- Action for opening attachment or manipulating all attachment links
- Filter wp_mail based on content type
- Add HTML to the bottom of each post in a post list
- get_the_archive_title hook unwanted changes!
- How to filter wp_get_recent_posts() to only posts that have thumbnails?
- Put data in my-account/view-order/id/ page
- What action/filter can be used for modifying the page to be rendered?
- Why can’t I shove an instance of a class into a variable from a do_action hook?
- Incrementing content with extra text after save/publish
- Adding user filter – Not updating data in URL
- wp_editor customization
- Passing a parameter to filter and action functions
- What problems could happen if I replaced add_filter and add_action with the function calling
- How to check which submission button was clicked?
- check, if any “add_action” function contains string XXXXXXXXX
- Why none of xmlrpc filters work
- WP Dashboard -> Posts-> Filter by Category -> Form Method Change : Which Hook
- Remove action added from class
- Custom search fields and AJAX support
- Adding to an array & passing it through do_action/apply_filters
- How to add a class to Buddypress avatars in the Activity stream? [closed]
- Hook into ‘when user logs in’ [persistent login]
- Hide H1 Title using the_title filter