December 30, 2024
1 min read
Essential Code Snippet For Web Developers

If you have comment active on your WordPress site but you dont want to keep website field then this might help you.

There is some plugin to do it but we are going to show with simple custom code as always.

Put this code on you theme functions.php file and you will see website field gone.

Functions.php
add_filter('comment_form_default_fields', 'unset_url_field');
function unset_url_field($fields){
    if(isset($fields['url']))
       unset($fields['url']);
       return $fields;
}

Now comment from might look like this. Look on remembering user text show “save my name, email, and website” it funny as you did not have any website field.

July 7, 2020
WordPress comment from without website

So, now let change this text to just simple Remember Me! and here is your code

Functions.php
add_filter( 'comment_form_default_fields', 'mukto_comment_save_text' );
function mukto_comment_save_text( $fields ) {
	$commenter = wp_get_current_commenter();

	$consent   = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"';

	$fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' .
					 '<label for="wp-comment-cookies-consent">'.__('Remember Me!', 'textdomain').'</label></p>';
	return $fields;
}

if you want to remove that checkbox completely this can help

Functions.php
add_filter( 'comment_form_default_fields', 'wc_comment_form_hide_cookies' );
function wc_comment_form_hide_cookies( $fields ) {
	unset( $fields['cookies'] );
	return $fields;
}

That’s all, Read our Cookie Popup with jQuery tutorial to accpet cookies permission

Leave a Reply

Your email address will not be published. Required fields are marked *

2 Comments

WooCommerce Custom Order Dropdown Based on Payment Method

WooCommerce admin order page custom drop-down base on payment method & show order admin column with code only

Allow Only Business Email Addresses in the Email Field of Elementor Forms

Find out how to restrict email fields in Elementor forms to business emails only. Improve form data quality by blocking free email domains like Gmail and Yahoo.

Enable Leverage browser caching & Compression

To speed up your website and get good score, Enable Leverage browser caching & Compression

Jquery Replace specific text in all element

Scenario Imagine you have a set of elements with the class specific_class, and they all contain the phrase “old text.” You want to replace this phrase with “New text” programmatically. The Solution Here’s a simple jQuery script to achieve this: How It Works Things to Keep in Mind Extending the Script jQuery provides a quick […]

Web Development Project in mind?

if you looking for a web developer for paid contribution to your project I am available for work.

Mukto
Mukto

Click the button below to chat with me.