🚀 Is building a website too difficult? Let me guide you step by step—Learn about the 「Naibabiji WordPress Website Building Coaching Service」 →

Tutorial on Adding Background Text to WordPress Comment Box

Because I recently switched toHummingbird Plugin for cachingWordPress Posts, and Hummingbird's cache update mechanism is somewhat unscientific—updating the cache requires clearing everything and regenerating it. When someone comments, if the page is not set to update the cache, the comment won't be displayed, so I researched adding prompt text to the WordPress comment box.The effect is as follows:   WordPress评论框背景文字 Implementation method:There are two methods found online for adding background prompt text to the WordPress comment box. Most articles use Method 1, but in recent years, especially now, Theme files are generally not written that way anymore, so most are implemented via Method 2. It depends on how your Theme is implemented.

Method 1

If in your Theme's comments.php file you can directly find code similar to the following string
Then you can add it directly within this string of code.

Method 2

If you cannot see the above string of code ', ) ); ?>For the string cols="45" rows="8" maxlength="65525", you can check what your Theme"s default Frontend displays and replace it with the Theme"s code. Default comment area code
$fields =  array(

  'author' =>
    '

' . '

', 'email' => '', 'url' => '

' . '

', );
Starting from 4.9.6, if „Show comments cookies opt-in checkbox“ is checked in „Discussion Settings“, a cookie consent checkbox will be added to the area.
$fields['cookies'] =  '';
Note: To use the variables from the above code in a custom callback function, you must first set these variables in the callback using the following:
$commenter = wp_get_current_commenter();
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true'" : '' );

$consent = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"';
This article references the following articles:Adding Guidance Instructions to WordPress Comment Box Custom Comment Form comment_form() WordPress Official Documentation Function Reference/comment form

🚀 Still feeling confused after reading the tutorial? Let me guide you step-by-step instead.

「Naibabiji WordPress Website Building Coaching」 — From selecting a domain and purchasing hosting to installing themes and publishing posts, I「ll guide you through every step, helping you avoid detours and reach your goals directly.

👉 Learn about Website Building Coaching Service
🔒

Comments are closed

The comment function for this article is closed. If you have any questions, please feel free to contact us through other channels.

×
二维码

Scan to Follow