I know it’s a bad idea to use AI Code if you yourself aren’t fluent in the language.. That said, I have a code snippet that works for me, and the code ChatGPT wrote that does NOT work. Could you ELI5 why ChatGPT’s code doesn’t work? It looks perfect to me.

[ad_1]

Code goal:

Replace the words in the WP comment cookie consent that must be checked before commenting when not logged in.

CODE THAT WORKED:

function customize\_comment\_form\_cookies\_consent\_label( $translated, $original, $domain ) {

$strings = array(

‘Save my name, email, and website in this browser for the next time I comment.’ => ‘Save my name & email in this browser for the next time I comment.’

);

if ( ! empty( $strings\[$original\] ) ) {

$translations = &get\_translations\_for\_domain( $domain );

$translated = $translations->translate( $strings\[$original\] );

}

return $translated;

}

add\_filter( ‘gettext’, ‘customize\_comment\_form\_cookies\_consent\_label’, 10, 3 );

ChatGPT’s code that DIDNT WORK:

function change\_comment\_cookies\_consent\_text( $translated\_text, $text, $domain )

{

if ( $text === ‘wp-comment-cookies-consent’ )

{

$translated\_text = \_\_( ‘New Label Text’, ‘your-text-domain’ );

}

return $translated\_text;

}

add\_filter( ‘gettext’, ‘change\_comment\_cookies\_consent\_text’, 20, 3 );

[ad_2]
1 Comment

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer