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”?
- Filter specific shortcode output?
- How to hook into unregistering a widget instance?
- How do I Make a Theme “plugin-ready”?
- How to disable all WordPress emails modularly and programatically?
- How do I know if author field was changed on post save?
- Load different template file when condition met?
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- Is it possible to create an action hook using do_action() within add_action()?
- Filter all html output
- Which hook is fired when inserting media into a post
- Making a class available via actions filters
- Filter list by a unique meta value dilemma
- return values from hooks do_action and apply_filters, which is better
- Return a custom value in a function added to an action hook
- Is there a filter called ‘network_admin_init’?
- Are there actions or filters I can use for Ajax calls?
- Using wp_handle_upload() to Direct Specific Path by Using $overrides
- Post Content, Special Characters and Filters
- Correct method of redirecting user login
- How to filter for user registration, be able to throw error message
- How to validate recaptcha on comments form?
- Customize title, description and focused keyword [closed]
- Filter Posts from the Main Query
- Filtering the post list in the admin area
- How to check if a protected hook is hooked?
- Gutenberg Block – Post Featured Image Filter Hook
- Filter for when the post is updated
- remove_action not removing add_action from constructor
- Filter get_page_by_path()
- Renaming wordpress login and get new password button
- Display taxonomy with a maximum number of letters
- Hook in a sidebar widget and add some markup
- ‘manage_users_custom_column’ is a filter, but ‘manage_posts_custom_column’ is an action. Why?
- comment_notification_text filter not working
- Scanning for custom embed and prefetching
- Modify author url display in edit-comments.php
- Remove and replace woocommerce add to cart button [closed]
- Save_post – Warning: Cannot modify header information
- Modify WordPress Page Title ()
- 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
- Re-order search results with posts_orderby filter and post meta value
- How to add a class to Buddypress avatars in the Activity stream? [closed]
- Updating User Profile on Registration
- can’t output gray scaled image I’ve created using add_image_size