I think you could use the comment_form_field_comment() filter to add the custom HTML before the main comment field. The filter is fired for both visitors and loggedin users.
add_filter( 'comment_form_field_comment', 'wpse_426971_comment_form_field_before' );
function wpse_426971_comment_form_field_before( string $field ): string {
return sprintf(
'<p>%s</p>%s',
is_user_logged_in() ? "I'm logged in" : "I'm not logged in",
$field
);
}
Or you can use the other dynamic comment_form_field_{$name} filters, if you want to add content before or after the other fields.
Related Posts:
- Earliest hook to reliably get $post/$posts
- How to pass/get data to/from the WooCommerce data-product_variations object?
- How to check if a hook is hooked or not?
- Passing Additional Parameters to add_filter Callable
- Modify WordPress Rest Api Request/Response
- How to add some custom HTML into wordpress admin bar?
- Custom theme hooks / filters – passing arguments
- How to hook wp_list_pages?
- How to make post and comment count unclickable with dashboard_glance_items hook
- How to use the_excerpt in a filter hook?
- Hook into admin post list page
- How to limit the pages displayed for choosing parent page on page attribute’s menu?
- How can I hide all posts that don’t have a thumbnail?
- Change text of Description in Image Library
- Am I using the right hook for removing quicktags on the admin TinyMCE?
- About Hooks and Filters
- Should I use add_action(‘publish_post or add_filter(‘publish_post?
- How can I reliably and globally disable wptexturize?
- Customise Jetpack Publicize text
- WordPress RSS feed – filter RSS content by custom field value
- filter the_title problem in nav
- Filter the URL of next_posts_link & previous_posts_link
- How to get list of all hooks of current theme / plugin?
- How to replace any occurence of Gravatars with a local placeholder image?
- Sensei LMS Hooks to Remove Content
- What hook/filter can I use to add/edit/show/hide the title under (on hover) links on the table view?
- Change WordPress RSS link with filter?
- Add a header before fields added with the attachment_fields_to_edit() filter
- Hide content editor for posts after approriate date
- Gutenberg disable the “block” tab in right sidebar
- Why my admin doesn’t work after adding rest_prepare_post filter?
- add_filter() function misunderstanding
- When to use actions and when to use filters
- add_filter to ‘woocommerce_before_main_content’ [closed]
- Editing
- Same Conditionals Not Working on Two Different Hooks
- Filter or Hook to catch pre-rendering of post content
- Can the wp_filter object hold multiple values with the same key
- check to see if hook is available
- apply_filters/do_action tag characters limit
- How do I target a single page to modify the comment form of only that page?
- How to removes all instances of thumbnails displayed in my theme?
- Insert term when page is published – avoid duplicates after edits
- How to modify core when there is no hook?
- When does a function assigned to the content_filtered_edit_pre filter hook fire?
- Capture post content before page renders
- Remove_action does not work
- Better extend a class or use add filter/action hooks?
- Add content as soon starts
- Make an array filterable per hook
- How do I add a checkmark to my-sites save settings hook
- Comment search plugin
- how to customize rss feed tags using hooks?
- How to filter backend post list showing only posts having a shortcode
- Add Lightbox To WordPress Native Gallery
- How can I replace an oEmbed URL in post with actual embed HTML
- Woocommerce “added to cart” message on main(home) page
- Detect when gutenberg editor title is available in Dom after editor load
- Is it possible to bind a function to a filter hook via Ajax?
- How do I hook my function to run only after submitting login form
- Prepending character(s) to a custom tag title?
- Change custom post type GUID in RSS
- filter hook to load a different post/page on current post/page
- Modify existing plugin function with add_filter
- Remove tags without a specific meta key from “choose from the most used tags”
- Redirect to woocommerce checkout after adding to cart – item already in cart
- What is the action hook to use if you want to capture the new password during password change?
- How can I edit comment meta value before it is saved?
- an action hook when a post reaches a certain number of views
- Action hook to control access to certain parts of my site
- Need to return shortcode text instead of the output
- Where exactly does the edit_{taxonomy} hook fire?
- Is there any reason for the nested filters to be applied on the first case and not in the second one?
- Replace Data In Post & Update Meta Field Post Is Saved
- Filter Media by attached page or blog post in Library
- How do I add a line break to a string that is output by PHP?
- How to add custom media library mime icons?
- Right filter for rewriting page statuscode
- Add filter return false not working
- Security question – Display a General Custom Login Error Message
- 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?
- Hook inside a hook
- Incrementing content with extra text after save/publish
- How to check which submission button was clicked?
- WP Dashboard -> Posts-> Filter by Category -> Form Method Change : Which Hook
- Hide H1 Title using the_title filter
- Add class to all parent elements inside the_content
- Filter dashboard custom post listing by user
- Getting entry ID from frm_email_message filter in formidable
- Auto append text after the title?
- Admin New Order: Autofocus on Search a product
- How to filter part of a variable if it is no array?
- Can you call a filter hook by “add_action”?
- How to Dynamically Switch WordPress Front Page Without Causing Canonical Redirect?
- Why wordpress doesn’t allow to add author filter to media library page in grid mode
- Core/Image access caption in render_template and in wp.hooks
- Ship block templates or block template parts with plugins