5 Code Snippets That WordPress Users Can Follow For Theme Customization
Join the DZone community and get the full member experience.
Join For FreeBelow is a list of 5 useful code snippets that you can use to customize your WordPress theme effectively:
Lessen Post Revisions
WordPress comes with a feature that saves a draft of a page and post – when an article is saved. This feature helps bloggers to review the drafts containing the previous versions of their work, especially during a lost connection. However, the drafts take a lot of space in the database and as they grow in number, your site's performance will eventually degrade. To resolve this issue, it is recommended that you should set the number of revisions you would like to save in your site's database. For this purpose, simply copy and paste the following code snippet in your wp-config.php file:
define('WP_POST_REVISIONS', 6);
You can also choose to disable WordPress revision, using the code as follows:
define('WP_POST_REVISIONS', false);
Remove Links From Comments
Often while providing feedback users insert links in the comments. As soon as the comments are approved and posted on your site, a link turns becomes clickable. However, spammers can exploit those links by replacing them with a link that leads to a "spammy" page. A viable alternative to avoid such situation is to add filter to keep the links added in the comments as plain text, by disabling their click-ability (as shown in the below given code):
remove_filter('comment_text', 'make_clickable', 8);
Empty Your Trash Folder
WordPress keeps a copy of all your website posts, pages and comments that you delete. In order to delete the things permanently, you will need to go to the trash folder. While this saves you from losing your data from being lost, it consumes more memory. Though, WordPress clean up the trash automatically after 30 days, but you can reduce it by adding the below code snippet in wp-config.php file:
define ('EMPTY_TRASH_DAYS', 5); // this will empty your trash after 5 days
In order to optimize your database, you will need to make sure that unnecessary items are not stored in your database. For this, you can disable the trash system just add the following line of code to your wp-config.php file:
define ('EMPTY_TRASH_DAYS', 0);
Changing “Howdy” Text
You may have stumbled upon a number of WordPress sites featuring the 'Howdy' text. If you don't want this text to appear on your site, all you need to do is to add the below given code to your functions.php file:
function change_howdy($translated, $text, $domain) {
if (false !== strpos($translated, 'Howdy'))
return str_replace('Howdy', 'Hello', $translated);
return $translated;
}
add_filter('gettext', 'change_howdy', 10, 3);
Adding a Favicon to Your Blog
Adding a favicon to your blog helps in making it a separate identity. Here's a simple code that lets you add a favicon in your site's header section. Make sure to add this code in your header.php file, or you can even add the code in your functions.php file:
function blog_favicon() {
echo '<link rel="Shortcut Icon" type="image/icon1" href="'.get_bloginfo('wpurl').'http://exampledomain.com/favicon.ico" />';
}
add_action('wp_head', 'blog_favicon');Note: When developing your theme, make certain to upload the “.ico” file in your theme's root folder (i.e. the one where the blog is uploaded). Doing so, can eliminate constant worry about changing the favicon's URL.
Conclusion
Here's hoping that the aforementioned code snippets will help you customize your theme in an effective and quick manner.</p>
This contribution of awesome post is given Samuel Dawson- a top-notch professional in Designs2HTML Ltd a convincing markup conversion firm which involves in the process of html to wordpress with efficient tactics. Samuel also do very deep research in this field.
Opinions expressed by DZone contributors are their own.
Comments