Support » Fixing WordPress » Comment cookies consent text

  • curtiskessler

    (@curtiskessler)


    Somebody in this thread shared a filter for changing the text on the comment cookies consent form label:

    function comment_form_change_cookies_consent( $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">Your modified text here</label></p>';
    	return $fields;
    }
    add_filter( 'comment_form_default_fields', 'comment_form_change_cookies_consent' );

    The problem with this code is that it disables the ability for the site admin to disable the cookies consent form from within the admin discussion settings.

    Is there a way to edit the text of the label, while still allowing the admin who is using my theme to disable the form altogether if desired?

Viewing 1 replies (of 1 total)
  • Shariq Khan

    (@shariqkhan2012)

    @ibetslott88 Please start a new thread stating your issue

    @curtiskessler If the code snippet is working fine except for the issue is admin discussion settings, then you could wrap the code inside a conditional check so that it executes only on the frontend, and leaves the admin settings intact.

    
    
    function comment_form_change_cookies_consent( $fields ) {
    	if( !is_admin() ) {
    		$commenter = wp_get_current_commenter();
    		$consent   = empty( $commenter['comment_author_email'] ) ? '' : ' checked=&quot;checked&quot;';
    		$fields['cookies'] = '<p class=&quot;comment-form-cookies-consent&quot;><input id=&quot;wp-comment-cookies-consent&quot; name=&quot;wp-comment-cookies-consent&quot; type=&quot;checkbox&quot; value=&quot;yes&quot;' . $consent . ' />' .
    						 '<label for=&quot;wp-comment-cookies-consent&quot;>Your modified text here</label></p>';
    	}
    	return $fields;
    }
    add_filter( 'comment_form_default_fields', 'comment_form_change_cookies_consent' );

Viewing 1 replies (of 1 total)
  • The topic ‘Comment cookies consent text’ is closed to new replies.