[Resolved] Trying to get website URL field not to appear

Home Forums Support [Resolved] Trying to get website URL field not to appear

Home Forums Support Trying to get website URL field not to appear

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1648345
    Matthew

    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.

    #1648491
    Ying
    Staff
    Customer Support

    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 ๐Ÿ™‚

    #1648845
    Matthew

    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.. :-/).

    View post on imgur.com

    #1649457
    Leo
    Staff
    Customer Support

    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.

    #1649995
    Matthew

    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;
    }
    #1650728
    Leo
    Staff
    Customer Support

    Glad to hear ๐Ÿ™‚

    #1840342
    Donna

    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.

    #1840389
    David
    Staff
    Customer Support

    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.

    #1841320
    Donna

    Thank you David. It’s good to know what does and does not belong with the Hook Elements. I’ll try Code Snippets.

    #1841464
    David
    Staff
    Customer Support

    You’re welcome

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.