- This topic has 9 replies, 5 voices, and was last updated 2 years, 9 months ago by David.
-
AuthorPosts
-
February 6, 2021 at 9:01 am #1648345Matthew
Hi
I’ve tried this: https://generatepress.com/forums/topic/how-to-remove-url-field-from-wordpress-comment-form/page/2/?bbp_reply_to=1150997&_wpnonce=0a7005cc36#new-post
And tried clearing the cache but the Website URL field still shows up.
Any ideas? I can’t figure out why it keeps showing up.
February 6, 2021 at 12:44 pm #1648491YingStaffCustomer SupportHi Matthew,
How did you add the code in? and are you using the exact code from here?
https://generatepress.com/forums/topic/how-to-remove-url-field-from-wordpress-comment-form/page/2/#post-1150997This should help, just make sure you’ve done the first step:
https://docs.generatepress.com/article/remove-e-mail-and-url-field-from-comment-form/Let me know ๐
February 7, 2021 at 2:47 am #1648845MatthewYeah I copied this exact code.
I did try the first step but it didn’t make any difference, I didn’t think this would, I would also prefer to keep the requirement to fill in name and email on.
I am using Toolset’s custom code to enable the code snippet (I use this all the time without any issues.. :-/).
February 7, 2021 at 11:42 am #1649457LeoStaffCustomer SupportI just tried this code and it worked to remove the website URL field only:
add_action( 'after_setup_theme', 'tu_add_comment_url_filter' ); function tu_add_comment_url_filter() { add_filter( 'comment_form_default_fields', 'tu_disable_comment_url', 20 ); } function tu_disable_comment_url($fields) { unset($fields['url']); return $fields; }
See test here with both GP and Twenty-twenty:
https://www.screencast.com/t/UxDTAET4KMake sure your cache is cleared. If not, then give Code Snippets a shot.
February 8, 2021 at 3:15 am #1649995MatthewHi
I tried with Code Snippets but no luck. Instead I used the following and it worked in case anyone else has this issue:
add_filter('comment_form_default_fields', 'website_remove'); function website_remove($fields) { if(isset($fields['url'])) unset($fields['url']); return $fields; }
February 8, 2021 at 10:41 am #1650728LeoStaffCustomer SupportGlad to hear ๐
June 30, 2021 at 3:20 pm #1840342DonnaUpdate: this should not be done in GP Elements. Use a child theme or Code Snippets instead.
Are there issues doing this through Generate Press Elements? The hook element code below removed the website URL from the comments form for me even when “Comment author must fill out name and email” was checked. I only tried it in my localhost environment so who knows.I added a new Hook Element to the “generate_before_comments_container” hook with the following PHP code:
<?php
add_filter(‘comment_form_default_fields’, ‘unset_url_field’);
function unset_url_field($fields){
if(isset($fields[‘url’]))
unset($fields[‘url’]);
return $fields;
}
?>I’m not sure if generate_before_comments_container was the correct hook to use, but it worked.
June 30, 2021 at 4:39 pm #1840389DavidStaffCustomer SupportHi there,
that needs to go in your child themes functions.php or added using the Code Snippets plugin.
The Hook Element is for adding ‘code’ into the theme templates, and you should not useadd_filter
funcitions within them as they need to be executed before WP parses the template.July 1, 2021 at 9:21 am #1841320DonnaThank you David. It’s good to know what does and does not belong with the Hook Elements. I’ll try Code Snippets.
July 1, 2021 at 12:12 pm #1841464DavidStaffCustomer SupportYou’re welcome
-
AuthorPosts
- You must be logged in to reply to this topic.