You’re right that comment_form
hardcodes the <form>
tag, so you cannot modify it with a filter or action. Adding your custom attribute with jquery would be possible, but then it wouldn’t be in the source code and hence not be picked up by search engines you might be targeting. The alternative is to buffer the entire output of the function and do a search and replace there. Like this:
ob_start ('wpse193237_add_attribute_to_form');
comment_form();
ob_end_flush();
function wpse193237_add_attribute_to_form ($buffer) {
return (str_replace ('<form', '<form data-my-custom="my_value"', $buffer));
}
Related Posts:
- Am I using the right hook for removing quicktags on the admin TinyMCE?
- How to enable visual editor when editing comments on the dashboard?
- Why anything done on comments_array hook gets reset?
- How do I target a single page to modify the comment form of only that page?
- Comment search plugin
- Use of comment_reply_link_args filter
- comment_for() Custom fields not visible when user is logged in
- Use has_filter on comment_post
- How can I filter the comment action links so that I can display the actions links based on user capabilities?
- Converting restricted html in comments to bbcode
- How many filter/action hooks are healthy?
- Filter specific shortcode output?
- Earliest hook to reliably get $post/$posts
- What does (10, 2) mean when used with add_filter
- Clarification on filters and hooks
- Valid characters for actions, hooks and filters
- How to hook into unregistering a widget instance?
- 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
- Hook to edit an column on comments screen?
- How to disable all WordPress emails modularly and programatically?
- How to hook wp_list_pages?
- How to use the_excerpt in a filter hook?
- Hook into admin post list page
- Change text of Description in Image Library
- Load different template file when condition met?
- About Hooks and Filters
- Should I use add_action(‘publish_post or add_filter(‘publish_post?
- Too many actions/filters!
- How to get list of all hooks of current theme / plugin?
- Which hook is fired when inserting media into a post
- Adding custom column to comments admin panel?
- Changing a WordPress core function without hacking core
- Change WordPress RSS link with filter?
- add_filter() function misunderstanding
- Is it possible to track down Actions and Filters?
- 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
- WP action/filter to modify title before header output and article output?
- Using wp_handle_upload() to Direct Specific Path by Using $overrides
- Post Content, Special Characters and Filters
- How to filter for user registration, be able to throw error message
- Gutenberg – Add align controls to a custom block
- How to remove action with slashes and arrows?
- How to validate recaptcha on comments form?
- changing font size and font of a custom message added after comment
- Better extend a class or use add filter/action hooks?
- Add default user field to WooCommerce checkout [closed]
- Changing WordPress core without hacking core
- Customize title, description and focused keyword [closed]
- Plugin options, presets and filters : can you help me improve my workflow?
- Filtering Comment Reply Links (comment_reply_link_args) for “infinite replies” in nested comments
- how to customize rss feed tags using hooks?
- Filtering the post list in the admin area
- Woocommerce “added to cart” message on main(home) page
- How to check if a protected hook is hooked?
- Wrapping my head around add_filter
- Gutenberg Block – Post Featured Image Filter Hook
- Modify message displayed on post save
- Change custom post type GUID in RSS
- Pass debug_backtrace() in WordPress filter
- filter hook to load a different post/page on current post/page
- Remove actions/filters that are set with create_function()
- Redirect to woocommerce checkout after adding to cart – item already in cart
- How to access page variable inside action hook
- I need to hook and change language of facebook sdk
- How To Get Search Term and Use in Function
- Renaming wordpress login and get new password button
- How do I add tags to entire comments, not just their text
- Same URL for portfolio and for a page creates 404 error. Is there any filter that i can use for a child page?
- comment_notification_text filter not working
- How do I add a line break to a string that is output by PHP?
- Scanning for custom embed and prefetching
- Filter widget_posts_args not working
- Modify author url display in edit-comments.php
- Filter the title to only affect the_title() template function
- Remove and replace woocommerce add to cart button [closed]
- style_loader_tag not changing stylesheet to preload
- Hook to change the site URL
- Modify WordPress Page Title ()
- Right filter for rewriting page statuscode
- Re-order search results with posts_orderby filter and post meta value
- How to filter wp_get_recent_posts() to only posts that have thumbnails?
- Adding user filter – Not updating data in URL
- How to check which submission button was clicked?
- Why none of xmlrpc filters work
- How to add a class to Buddypress avatars in the Activity stream? [closed]
- Which hook should be used in this case?
- Getting entry ID from frm_email_message filter in formidable
- Auto append text after the title?
- How to use apply_filters(‘get_calendar’) to change get_calendar() output?
- Better way to change the default password reset url with the woocommerce one?
- How to elect position of new item output in a dropdown when using add_filter
- Replacing text using add_filter
- Change password reqts with NO plugin without breaking resetpass link?