In order to make the site unique and functional, some webmasters now take advantage of the useful code snippets to modify their websites, enhancing the performance and functionality to a large extent. However, we have found that many people, especially beginners, simply give up this method but install some related plugins to extend the power of their websites, for they think this practice needs a certain level of advanced knowledge to come out the coding stuff. In this case, we’d like to introduce some of the most popular and widely used WordPress code snippets in the following. Thus, all you need to do is to copy and paste these lines of code into the functions.php file of your WordPress theme. You can find this file from /wp-content/themes/themename/folder, or login to your WordPress dashboard and navigate to Appearance < Editor.
Remove the Trash
There is a recycle bin available in WordPress that acts as a backup to collect all your deleted posts, pages, image, files, and comments. If you want empty the trash, you need to delete these copies permanently in the trash folder. In fact, WordPress can clear out the trash automatically at a 30-day interval, and the days number can be reduced with the following lines of code.
Add Featured Image to WordPress Feeds
The featured image can be regarded as a graphical symbol of a specific post. Readers can guess what you are talking about in this article simply by checking the featured image. It is easy to add this kind of picture into the website post. However, if you are going to display it to your WordPress feeds, then you need the following code snippet.
Reduce Post Revisions
Every time you edit and save your drafted article, WordPress revision system will copy your previous drafts in case you may need the earlier draft. However, too many revisions will leave a huge burden to your site as it takes up a lot of storage for database, resulting in a low website speed on the Internet. In this circumstance, you need to control the number of post revisions to a moderate level with the help of coding stuff.
Remove URL Field from Comment Section
The code snippet used to achieve this purpose is useful for webmasters who suffer from comment spammers. Generally, these spammers increase their search engine rankings by adding links on your websites that are linked to them. These bad links can devalue your site and drive readers away, so you’d better try your best to remove them. Here, disabling the URL field in comment section can be regarded as one of the easiest methods.
Relocate WP-Content Folder
All your themes, plugins, uploads and some related valuable data are stored in your wp-content folder. Therefore, if hackers are going to attack your website, this folder can be a top target. In this case, you’d better move this folder from the regular directory to another place of your website.
Decide the Minimum Comment Length
This code is used to enforce a minimum length of your post comment. As the comment section plays a vital role to set up your website awareness, increase the search engine friendliness, and build a solid relationship with readers, some short comments like “it is great”, “cool”, “I agree” are less meaningful and useful. With these lines of code, however, you can decide the minimum number of characters allowed in each comment.
Add Post Titles for Preview and Review
This action can improve the reading experience for your readers and encourage them to read more content come out by you. After all, no matter which post they are going through within your website, they can know what the previous and the next posts are by looking at the post titles. If they are interested, they can click the link directly and easily.