I was asked by a visitor how he could change the message that appears just before the comments field in his WordPress blog.
This article assumes that you already have a blog running WordPress. If not, please start with How to Create a Blog.
You must actually be able to access the files and folders on your website directly, either via FTP/SFTP or from your web host's control panel (eg, through its file manager). This is because you will need to create a new directory (ie, folder) and upload 2 files into it. It will probably not be possible to do this if you are using a free blog host or a WordPress Hosting plan on a commercial web host. In general, in my experience, to be able to access files and folders directly, your site has to be on a shared web host.
I will also assume that you know how to use an FTP or SFTP program to upload files and create directories on your blog. A basic tutorial for a free FTP program called FileZilla can be found in How to Use FileZilla to Upload Files.
Alternatively, if you don't want to use an FTP or SFTP program, you can also use the file manager in your web host's control panel. It doesn't matter which method you use to create directories and upload files, so long as you can.
You will also need a plain text editor. You do not actually have to download one, since you probably already have it on your system. For example, Windows systems come with Notepad preinstalled, and Mac OS X with TextEdit.
If you use the one of default themes that come with WordPress, there is typically a comment field at the bottom of each post with some instructions or message that appears before it. For example, the Twenty Sixteen theme has a section with the title "Leave a Reply" and a brief paragraph that says "Your email address will not be published. Required fields are marked *".
While you can of course search the theme files in the "wp-content/themes/
" folder,
and alter the text directly, your changes will be overwritten the next time the theme updates.
And you should not simply prevent the theme from updating, since it may contain crucial
security fixes.
The alternative is to create what is known as a "child theme". The latter only contains the changes you want to make to the main theme (called the "parent theme") and nothing else. The parent theme contains the rest of the files needed to make your blog appear the way it does. When WordPress updates itself, it will only update the parent theme, leaving your child theme untouched. This way, you get the best of both worlds: an up-to-date theme, and your changes untouched.
A child theme is fairly easy to make, particularly if all you want is to modify the instructions for the comments field.
Log into your Wordpress blog and find out the name of the theme you are currently using.
Connect to your website with your FTP software, and navigate to the wp-content/themes
directory.
That is, doubleclick to get into the wp-content
folder. Then look for a sub-directory called
themes
and doubleclick to open it.
Look for the name of your theme in that directory. For example, if you are using the Twenty Twenty theme,
the folder is called "twentytwenty
".
Create a new folder in that same directory and give it the name of your original theme with "-child
"
affixed to it. For example, if your current theme is stored in a directory called "twentytwenty
",
make a new directory with the name "twentytwenty-child
".
You can actually call the directory anything you like. However, the WordPress developers recommend that
you stick to the naming convention of calling your child theme by the original name with a "-child
"
suffix. It will also help you in the future, so that you do not mistake that folder to be one with a
self-contained theme, and accidentally delete the parent.
Note down both the name of the parent theme's folder as well as the child theme's folder. You will need both.
Leave your FTP software running, and connected to your website. You will need it again later.
Open a plain text editor on your computer. For example, if you are currently using Windows, click the Start menu and type "notepad". Click the "Notepad" entry that appears at the top of the menu to run it. Those who are using Mac OS X should do the equivalent to start TextEdit.
Copy the text in the box below and paste it into your editor. I suggest that you do not manually type it, but copy and paste as I said (to avoid typing errors). To copy and paste, just drag your mouse over the text in the box to highlight it, then click the right mouse button to bring up the browser's context menu. Click "Copy" in that menu. Then switch to your editor and paste it the usual way. For Notepad, you can paste it by clicking "Edit" in the menu bar, followed by "Paste" in the drop down menu that appears.
Copy and paste everything above, including the line that says "/*
" and the line
that says "*/
". Don't worry that it currently doesn't reflect your actual theme names.
You will change it in the next step.
Now, in your editor, change the line "Template: twentysixteen
" to refer to
your parent theme's directory. For example, if your parent theme is
in a directory called "twentytwenty
", change it to "Template: twentytwenty
".
Remember that this is the directory name. It is not the human-readable name that you see in your WordPress interface. The name must be exactly the folder name you saw earlier.
Change the "Theme Name
" line to refer to the name of your theme, but with the word "Child" appended.
For example, if your theme is called "Twenty Twenty", change the line to say "Theme Name: Twenty Twenty Child
".
This name will appear in your WordPress user interface, so don't write anything that will confuse you
later. For example, don't be too clever and call it by some fancy new name, or years down the line, you
may forget which parent theme this one is linked to. Keep the name of the original theme and add "Child" to it.
The "Description
" line is optional, and you can change it to whatever you want. You can even
delete it if you wish.
Save the file with the name "style.css
". Note that you must use this name, and
no other, or WordPress won't recognize it. If you are using Notepad, click "File" on the menu bar, followed by
"Save As..." in the menu that appears. Then type "style.css"
, including the
quotation marks. You must include the quotation marks if you use Notepad, otherwise the editor
will change your filename to "style.css.txt
" behind your back. And if you did not
configure
Windows to show you the file extensions, you will not be able to see that your file has now the wrong name.
Close your text editor. That is, exit the program.
In your FTP software, change to the child theme's folder. For example, if the folder is called
"twentytwenty-child
", doubleclick to open it in your FTP program.
Upload the "style.css
" file that you have just created to that folder.
Again, leave the FTP program open for now. You will need it again after the next few steps.
Open your plain text editor again. You should see a blank page. If you did not close it earlier as I suggested, and it still contains the "style.css" content, please close it first, so that you do not accidentally modify the wrong file. We are starting a new blank document here.
Copy and paste the following lines into your editor. Do not re-type it or you may make mistakes. (For example, your browser may have folded my long lines into multiple lines, so if you manually type it, you may incorrectly break lines.)
In addition, don't worry that it doesn't say what you want it to say. For now, just copy and paste it.
The text that will be shown under the "Leave a Reply" heading in the Twenty Sixteen theme (which was the theme I used for the above example, since it was what my visitor had) is given in this line:
This is actually the default text used by that theme. Modify it so that it says what you want it to say. If you are not familiar with the PHP programming language, notice that the text to be changed is contained within single quotation marks. Unless you know what you're doing (eg, you know how to write PHP programs), only modify the things contained within the quotation marks.
If you want single quotation marks (such as apostrophes) to appear in your instructions, precede each one
with a backslash (ie, the "\" character), otherwise the PHP interpreter won't know whether you are terminating
the quote or inserting an apostrophe. If you are not sure what I mean in my previous sentence, don't use any
apostrophes or single quotation marks in your modification (eg, rephrase your sentence so that apostrophes are
avoided). If you're afraid you will break something, stick to changing these words only:
"Your email address will not be published. Required fields are marked
<span class="required">*</span>"
When you are done, save the file as "functions.php
". Again, if you are using Notepad, make
sure you include the quotation marks around the name, otherwise it will silently save it as
"functions.php.txt
" instead. Note that you should not use any other name. It must be literally
"functions.php
", small (ie, lowercase) letters and all, or WordPress will not recognize it.
Upload this file to the child theme's directory (where you previously transferred the "style.css
" file).
There should now be two files in that folder: "functions.php
" and "style.css
".
Disconnect from your site in your FTP program and exit it. Quit your text editor as well. The remainder steps have to be done within WordPress itself.
Log into your WordPress blog. Go to the Themes section, that is, the part where you normally choose a theme. You can usually do this by selecting "Appearance" in the left column, followed by "Themes" in the submenu that appears.
Look for the child theme that you created. There won't be a pretty picture for it (because you didn't create one for it earlier), but you can find it by looking for its name. Click the "Activate" button.
If you have customized your original theme, for example, to add menus, widgets, headers, etc, you will need to make those changes again. This is because WordPress treats the child theme as a new theme, separate from what you used earlier. Don't worry, your new theme still basically looks like the old one, since it inherits the default appearance the parent had (minus customizations to the menu, widgets, headers, etc), and your child theme didn't change anything except the words appearing before the comments/reply field.
Once you are done with the changes, log out of WordPress. You have to log out, otherwise you can't test your modifications. When logged in, you will only see the words that a logged-in user sees in the comments area, which is different from what a visitor who is not logged in sees.
Now go to one of the post pages where a comment field is shown, to see if you have correctly altered the text.
This section is only for those who understand PHP and know how to modify scripts written in that language.
Other parts of the comments area can be modified too. For example, if you want to change the
"Leave a Reply" header so that it now reads (say) "Leave a Message", you will need to add
the following line to the tsw_change_comments_field_message()
function, just
before the line that says return $comment_form_settings ;
.
You can find the full list of things that can be altered in comment form function reference in the WordPress Codex.
Copyright © 2020 Christopher Heng. All rights reserved.
Get more free tips and articles like this,
on web design, promotion, revenue and scripting, from https://www.thesitewizard.com/.
Do you find this article useful? You can learn of new articles and scripts that are published on thesitewizard.com by subscribing to the RSS feed. Simply point your RSS feed reader or a browser that supports RSS feeds at https://www.thesitewizard.com/thesitewizard.xml. You can read more about how to subscribe to RSS site feeds from my RSS FAQ.
This article is copyrighted. Please do not reproduce or distribute this article in whole or part, in any form.
It will appear on your page as:
How to Change the Message Shown Before the Comments Field in WordPress