Archived topic
Trying to get website URL field not to appear
9 replies · Started by Matthew on February 6, 2021
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.
Hi 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-1150997
This 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 :)
Yeah 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.. :-/).
I 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/UxDTAET4K
Make sure your cache is cleared. If not, then give Code Snippets a shot.
Hi
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;
}
Glad to hear :)
Update: 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.
Hi 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 use add_filter funcitions within them as they need to be executed before WP parses the template.
Thank you David. It's good to know what does and does not belong with the Hook Elements. I'll try Code Snippets.
You're welcome