We all want to get the most out of every website we run - and WordPress is no exception. When we first started this site, there were many things we couldn't figure out and we had to go it alone.

The authors of this website want to make sure you jumpstart your learning process and get the most out of WordPress right now! With WordPress being the CMS of choice for 30% of ALL websites on the internet, 40% of the top 10K sites, and with it being the CMS of choice for 50% of websites which use a CMS, we're sure we speak for many people when we say these WordPress tips will help you push WordPress blog to its full potential!

The great thing about WordPress is that its popularity has led to a large number of tips and tutorials available which can show you how to do lots of stuff, small WordPress tricks which push your website to its maximum potential.

WordPress has matured significantly over the years, from a humble blog to a CMS that is so flexible that it allows you to create any kind of website today. From a personal blog to an e-commerce site to a niche social network, you can count on WordPress and all kinds of WordPress themes to allow you to create a great website. Themes of note including the best-selling items, Divi and Avada which we've looked at and reviewed fully in separate posts here and here. We've got a full listing of themes and roundups we've looked and reviewed in detail in a specific section for this purpose in the menu above: WordPress > Themes.

And with the growth comes the need for WordPress tricks or "hacks" - small changes in the WordPress code to optimize the performance and display of WordPress.

However, most users are not developers and do not have much experience with code. Thus, many people are not able to use WordPress tricks to tweak and optimize their sites to add more functionality.

In this article we’ll show you how to do some cool WordPress tips without hiring a developer - these are a few simple WordPress tricks (or small tweaks/changes in WordPress code) which allow you to get more, much more from your WordPress website installation.

Why do we call these tricks or hacks? Wikipedia defines a programming hack as "an inelegant but effective solution to a computing problem". So since we are changing the WP files - we are calling these changes hacks - essentially it's just WordPress tips and tricks which you should use to make your overall WP experience healthier without having to go through a huge amount of tutorials.

Note: This article assumes you know that some basic HTML/CSS coding. If you're not ready to do any of these changes yourself, why don't you have a try and hire a WordPress developer from the top 3% of talent from Toptal? This way you'll all of the benefits without any of the hassle of coding involved.

You'll find that many of these tips involve changes to one of the template files, such as functions.php, single.php, headers or another file. Make sure you back up the files before making any tweaks on any of these files because errors might break your site and you will need to revert to a working version of the file.

Add new features to your WP site using the following tricks tips and tweaks. If you'd like to get more of these, we have a whole list here under WordPress > Tips and Tricks.

1. Compress Images for Faster Load Times

Images are one of the heaviest components of a webpage and if you’re not optimizing them, you’re hurting both your site’s performance AND your SEO.

Besides the fact that slow websites create a negative user experience.

To optimize your images, one of the most effective ways is to compress them. You can also make them smaller by using specific formats while also removing EXIF data.

There are many tools to compress your images without losing quality (or at worst, very little loss that's not even noticeable).

You can use online services, or else use specific programs that you'll need to install on your own machine.

For example, you can use one of the following programs:

Adobe Photoshop (Paid) GIMP (Free)

Both of these programs have an option to save your image for the web or settings that will make images optimized for the web so that they have a smaller size and therefore, load faster.

You can also do similar image compression using online tools such as:

TinyPNG JPEGMini Optimole EWWW Image Optimizer

These are either a WordPress plugin or an online service that you can use to compress your images before or as you upload them to WordPress.

While some might argue about the various features of each of these services or programs, it's always better to have any image compression tool or plugin rather than nothing.

We go into the merits of how to choose the best image compression plugin for WordPress or how to use Photoshop/GIMP to optimize your images for the web as these have been written countless times.

What’s important to know here is that you must optimize your images to improve your site’s performance and SEO.

2. Customize log in page

Adding a few tweaks on your functions file will let you customize your login page. Here’s what you need to do.

a) In your current theme directory (../wp-content/themes/your-theme-name), add a folder called “login”. Create a CSS file inside the login folder and name it custom-login-styles.css

b) Next, add the following code into your functions.php file

function my_custom_login() {

echo '<link rel="stylesheet" type="text/ css " href="' . get_bloginfo('stylesheet_directory') . '/login/custom-login-styles.css" />';

}

add_action('login_head', 'my_custom_login');

Simply customize your CSS file, custom-login-styles.css. This will reflect on the login page.

To change the logo which appears you can use the following, remember to tweak the values of the logo image to the ones on your own site. The size of the logo should be 80px by 80px

function my_login_logo() { ?> <style type="text/css"> #login h1 a, .login h1 a { background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/images/custom-login-logo.png); height:65px; width:320px; background-size: 320px 65px; background-repeat: no-repeat; padding-bottom: 30px; } </style> <?php } add_action( 'login_enqueue_scripts', 'my_login_logo' );

To change the name that appears with the logo you can use the following tweak in functions.php:

function my_login_logo_url_title() { return 'Your Site Name and Info'; } add_filter( 'login_headertitle', 'my_login_logo_url_title' );

You can also change the URL of the logo to your own custom URL:

function my_login_logo_url() { return "https://www.example.com"; } add_filter( 'login_headerurl', 'my_login_logo_url' );

3. Add custom page template into WordPress

It is possible to custom design a page with simple HTML/CSS and installs it on your site. All that needed is to simply add the following code into the top of your custom HTML page.

<? php /* Template Name: Squeeze */ ?>

After adding the code, save the page as squeeze.php and upload it to your current theme folder (../wp-content/themes/your-theme-name)

Once the file is uploaded, create a new page and choose the template Squeeze under ‘Page Attributes’. Publish the page to see it live.

4. Add infinite scroll WordPress trick

Automatically load new content when the reader scrolls down and approaches the bottom of the page. Infinite scroll is a Jetpack plugin feature. If you’re using a well-coded theme like the default WordPress theme, your theme will support infinite scroll.



Install the Jetpack plugin, enable infinite scroll feature and add the following code to your functions file.



add_theme_support( 'infinite-scroll', array(

'container' => 'content',

'footer' => 'page',

) );

5. Disable post revisions

‘Post revisions’ is one of the best features of WordPress. However, some users might not need this feature especially for those who have limited database space. This tip will enable you to save on space-related to storing of revisions



To disable the feature, add the following code to wp-config.php file



define('AUTOSAVE_INTERVAL', 120 ); // seconds

define('WP_POST_REVISIONS', false );



This code will disable all the future revisions, and it extends the autosave interval from 60 to 120 seconds. It means your post will be autosaving every 120 seconds. If you want to learn more about WordPress autosave, check out our full article here: https://www.collectiveray.com/wordpress-autosave

6. Add a customized CSS file

Add a customized CSS file with the name 'custom.css' to your theme by adding the following code to your functions file.

function custom_style_sheet() {

wp_enqueue_style( 'custom-styling', get_stylesheet_directory_uri() . '/custom.css' );

}

add_action('wp_enqueue_scripts', 'custom_style_sheet');

Make sure the new CSS file is located in the same directory as that of the main CSS file.

7. Install a child theme

To create a child theme add the below code to the CSS file of your child theme.

/*

Theme Name: Child Theme Name

Template: parenttheme

*/

@import url("../parenttheme/style.css");

Make sure you change <parenttheme> to the actual name of the parent theme and call the parent theme’s CSS file within your child theme’s CSS file. Use normal quotes instead of curly quotes. We also have a detailed tutorial on how to add a child theme and widget area here.

8. Use normal quotes instead of curly quotes

If you have ever shared a code snippet on WordPress, you might have noted that by default, WordPress turns normal quotes to smart codes, which could break the code snippet you're about to publish.

To disable this feature, insert the following code snippet to your functions.php file - another of those WordPress tips which seems small but is quite essential

remove_filter('the_content', 'wptexturize');

9. Display random image header

If you are a person who would love to display random image headers on your blog, this trick is for you.

Name your image 1.jpg, 2.jpg, 3.jpg, and so on. Upload those images to images folder inside your theme directory. Then, paste the following code to the header file.

<img src="https://Path_to_image_ folder/<?php echo(rand(1,10)); ?>.jpg" width="image_width" height="image_height" alt="image_alt_text" />

Make sure you replace the Path_to_image_folder with the actual path.

Incidentally, if you're looking to optimize the size of the images in your installation, you might want to look at this post from WPBuffs: Optimize Images 300% in WordPress with These 17 Free Tools and Plugins.

10. Delete existing post revisions

If you want not only to disable the post revision but also to delete all the existing revisions saved in your database, simply run the following SQL query from your PHPMyAdmin.



DELETE FROM wp_posts WHERE post_type = 'revision';

11. Add featured box inside the content

If you would like to add a featured box inside your post that stands out from the rest of the content, add the following code to the theme’s functions file.

function make_yellowbox($atts, $content = null) {

return '<p style="background: none repeat scroll 0 0 #ff9; clear: both; margin-bottom: 18px; overflow: hidden; border: 1px solid #e5e597; padding: 13px;">' . do_shortcode($content) . '</p>';

}

add_shortcode('yellowbox', 'make_yellowbox');

Once the code is added, any text wrapped inside the shortcode will appear in a featured yellow colored box.

[yellowbox]Your featured content here[/yellowbox]

12. Show related posts

Insert the below code to single file to show related posts without havint to install a plugin. This function uses tags to search for related posts and selects the first five (5) and displays their title.



<?php //for use in the loop, list 5 post titles related to first tag on current post

$backup = $post; // backup the current object

$tags = wp_get_post_tags($post->ID);

$tagIDs = array();

if ($tags) {

$tagcount = count($tags);

for ($i = 0; $i < $tagcount; $i++) {

$tagIDs[$i] = $tags[$i]->term_id;

}

$args=array(

'tag__in' => $tagIDs,

'post__not_in' => array($post->ID),

'showposts'=>5,

'caller_get_posts'=>1

);

$my_query = new WP_Query($args);

if( $my_query->have_posts() ) {

while ($my_query->have_posts()) : $my_query->the_post(); ?>

<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>

<?php endwhile;

} else { ?>

<h2>No related posts found!</h2>

<?php }

}

$post = $backup; // copy it back

wp_reset_query(); // to use the original query again

?>

Often, spam comments survive the spam filters and reach your ‘awaiting moderation’ list. Deleting it manually could be time-consuming. Follow the procedure to instantly delete thousands of such spam comments.

Log in to phpMyAdmin, select your website's database, click SQL and paste the code given below in the SQL command window.

DELETE from wp_comments WHERE comment_approved = '0';

And now your site is.

This is one of those WordPress tips which can really save you a ton of time!

There are plenty of other tricks you can use to make your installation leaner, cleaner and hence faster. For example, a couple of simple tricks you should enable:

Read More: 3 Ways to Enable WordPress GZip Compression (faster website)

Read More: [How to] Leverage Browser Caching in WordPress with or without a plugin [5 ways]

By default, WordPress combines both comments and trackbacks. Separating both can make things look more organized.

Step 1: Find the below code in the comments.php file.

<?php foreach ($comments as $comment) : ?>

Paste the below code after it.

<?php $comment_type = get_comment_type(); ?>

<?php if($comment_type == 'comment') { ?>

Step 2: Then, look for the below code

<?php endforeach; /* end for each comment */ ?>

Paste the below code before it

<?php } else { $trackback = true; } /* End of is_comment statement */ ?>

Step 3: Then, look for the following code

<?php else : // this is displayed if there are no comments so far ?>

Paste the below code before it

<?php if ($trackback == true)

{ ?> <h3>Trackbacks</h3>

<ol>

<?php foreach ($comments as $comment) : ?>

<?php $comment_type = get_comment_type(); ?>

<?php if($comment_type != 'comment') { ?>

<li><?php comment_author_link() ?></li>

<?php } ?>

<?php endforeach; ?>

</ol>

<?php } ?>

15. Increase PHP memory

If you were activating a huge plugin and found an error that says memory exhausted just add the following line of code to your wp-config.php file.



define('WP_MEMORY_LIMIT', '64M');



The above code will increase the memory limit to 64M, but you can change the value to whatever your hosting server can support. You should check whether the memory has increased to 64M by checking phpinfo() on your WordPress.

If you see that the memory did not change, contact your hosting to check whether you are allowed to reconfigure the memory and ask them to increase it for you.

WordPress automatically checks if plugins updates are available.

The below trick comes in handy, in some cases such as if you worry that updating plugins might break your site. Paste the following code to your functions file and disable checking for plugin updates.

WARNING: Disabling plugin updates could lead to your WordPress website being compromised. Enable this again once you're ready from your testing.

remove_action( 'load-update-core.php', 'wp_update_plugins' );

add_filter( 'pre_site_transient_update_plugins', create_function( '$a', "return null;" ) );

17. Increase/decrease maximum upload size through media uploader

Depending on the host, you’ll see a limit for the file size that you can upload through your Media uploader page in WP.



Add the below code to your .htaccess file to increase the upload limit to 64MB

php_value upload_max_filesize 64M

php_value post_max_size 64M

php_value max_execution_time 300

php_value max_input_time 300

We're not sure what files you need to upload which are larger than 64M, but if you do, WordPress tips like this can quickly solve your issue.

Conversely, if you need to decrease the size of files which can be uploaded, all you need to do is lower the value to something like 2M or whatever you prefer.

18. Redirect to a maintenance page

Sometimes you may need to redirect the site to a maintenance page. Create a maintenance page and name it as maintenance.html. Upload it to the root directory. Add the below code to .htacess and redirect all traffic to maintenance.html

# Redirect all traffic to maintenance.html file

RewriteEngine on

RewriteCond %{REQUEST_URI} !/maintenance.html$

RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123

RewriteRule $ /maintenance.html [R=302,L]

Don't forget to remove this once you are ready. Keep this for as short a time as possible because search engine crawlers such as Google will also be seeing this page instead of your regular content.

19. Custom error pages

Create error pages for 403, 404 and 500 errors and upload it to your base WordPress installation. Then, add the following code snippet to your .htaccess file to enable the custom error pages.

# Custom error page for error 403, 404 and 500

ErrorDocument 404 /404-error.html

ErrorDocument 403 / 403-error.html

ErrorDocument 500 / 500-error.html

To highlight the author's comments, find the following code in your CSS file.

.bypostauthor { background: #eee; }

21. Stay logged in for a long(er) period

By default, WordPress keeps you logged in for 2 weeks if you check the “Remember me” option while logging in.

Add the following code snippet to the functions within your theme so you can stay logged in to your site for a year. You can convert any time to seconds and update accordingly if you want to be longer or shorter.

We would suggest going for a month: 2629746 seconds

Of course, with this WordPress tip, you can choose whatever value you want, just find the number of seconds add replace the value.

add_filter( 'auth_cookie_expiration', 'stay_logged_in_for_1_year' );

function stay_logged_in_for_1_year( $expire ) {

return 31556926; // 1 year in seconds

}

Add the following code to functions file to customize the footer text on the WordPress dashboard.

function remove_footer_admin () {

echo "Your own text";

}

add_filter('admin_footer_text', 'remove_footer_admin');

23. Enable shortcodes on widgets

By default, WordPress widgets aren’t enabled to manage shortcodes. Add the following to functions file and empower your widgets to support shortcodes.



define('widget_text', 'do_shortcode');

24. Change the length of excerpts

By default, length of the excerpts in WordPress is 55 words. Tweak the functions by adding the following commands to customize the length so it can fit the layout.

function custom_excerpt_length( $length ) {

return 20;

}

add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

Add the following lines of code to enable another from the plenty of WordPress tips which uses hooks and the functions.php file of your theme

function wpb_most_commented_posts() {

ob_start();?>

<ul class="most-commented">

<?php

$query = new

WP_Query('orderby=comment_count&posts_per_page=10');

while($query->have_posts()) : $query->the_post(); ?>

<li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> <span class="wpb-comment-count"><?php comments_popup_link('No Comments;', '1 Comment', '% Comments'); ?></span></li>

<?php endwhile; ?>

</ul>

<?php// Turn off output buffering

$output = ob_get_clean();

return $output; }

add_shortcode('wpb_most_commented', 'wpb_most_commented_posts');

add_filter('widget_text', 'do_shortcode');

Then, add this shortcode in a widget wherever you want to display the most commented posts.

[wpb_most_commented]

Add the following code to your theme’s functions.php to customize the text before the comment form. Replace the text with your own preferred text.

function collectiveray_comment_text_after($arg) {

$arg['comment_notes_after'] = "We enjoy your constructive comments but please comment responsibly. Trolling, harassment or otherwise abusive behaviour will not be tolerated and further action will be taken as necessary.";

return $arg; }

add_filter('comment_form_defaults', 'collectiveray_comment_text_after');

If you delete old posts manually from MySQL, the tags you used on the posts will remain unused. Run the following SQL query to identify such unused tags. This is one of those WordPress tips which needs a bit of attention, because deleting stuff which is necessary can break your site.

SELECT * From wp_terms wt

INNER JOIN wp_term_taxonomy wtt ON wt.term_id=wtt.term_id WHERE wtt.taxonomy='post_tag' AND wtt.count=0;

28. Redirect mobile users to mobile site

This trick comes in handy if you like to keep a mobile version of your site to the responsive version. Add the following commands to the .htaccess file to redirect the mobile users to a mobile version of the site.

RewriteEngine On

# Check for mime types commonly accepted by mobile devices

RewriteCond %{HTTP_ACCEPT} "text\/vnd\.wap\.wml|application\/vnd\.wap\.xhtml\+xml" [NC]

RewriteCond %{REQUEST_URI} ^/$

RewriteRule ^ https://m.domain.com%{REQUEST_URI} [R,L]

29. Remove help and screen options from dashboard

This WordPress tip cleans your admin dashboard from unnecessary clutter. You can see the options “help” and “screen” on the top right hand side of your WP dashboard. Add the following code to functions to remove these options from the dashboard.

add_filter( 'contextual_help', 'wpse_25034_remove_dashboard_help_tab', 999, 3 );

add_filter( 'screen_options_show_screen', 'wpse_25034_remove_help_tab' );

function wpse_25034_remove_dashboard_help_tab( $old_help, $screen_id, $screen )

{

if( 'dashboard' != $screen->base )

return $old_help;

$screen->remove_help_tabs();

return $old_help;

}

function wpse_25034_remove_help_tab( $visible )

{

global $current_screen;

if( 'dashboard' == $current_screen->base )

return false;

return $visible;

}

30. Show popular posts in the sidebar

To show the 5 most popular posts according to the comments count, place the below lines in the sidebar.php file. Of course, if you want to show more or less than 5, just change from 5 to another value you prefer in the $result line.

<h2>Popular Posts</h2>

<ul>

<?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5");

foreach ($result as $post) {

setup_postdata($post);

$postid = $post->ID;

$title = $post->post_title;

$commentcount = $post->comment_count;

if ($commentcount != 0) { ?>

<li><a href="<?php echo get_permalink($postid); ?>" title="< ?php echo $title ?>">< ?php echo $title ?></a> {<?php echo $commentcount ?>}</li>

<?php } } ?></ul>

To add breadcrumbs, add the following lines to your functions file.

function the_breadcrumb() {

echo '

<ul id="crumbs">';

if (!is_home()) {

echo '

<li><a href="';

echo get_option('home');

echo '">';

bloginfo('name');

echo "</a></li>

";

if (is_category() || is_single()) {

echo '

<li>';

the_category('title_li=');

if (is_single()) {

echo "</li>

<li>";

the_title();

echo '</li>

';

}

} elseif (is_page()) {

echo '

<li>';

echo the_title();

echo '</li>

';

}

}

elseif (is_tag()) {single_tag_title();}

elseif (is_day()) {echo"

<li>Archive for "; the_time('F jS, Y'); echo'</li>

';}

elseif (is_month()) {echo"

<li>Archive for "; the_time('F, Y'); echo'</li>

';}

elseif (is_year()) {echo"

<li>Archive for "; the_time('Y'); echo'</li>

';}

elseif (is_author()) {echo"

<li>Author Archive"; echo'</li>

';}

elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "

<li>Blog Archives"; echo'</li>

';}

elseif (is_search()) {echo"

<li>Search Results"; echo'</li>

';}

echo '</ul>

';

}

After that, add this line of code to your theme’s template where you would like the breadcrumbs to show up (e.g. single.php, archives.php, etc.).

< ? php the_breadcrumb(); ?>

32. Customize your sidebar for individual posts

Display customized sidebar content for individual posts using custom fields. At first, find the following line of code in your single.php, index.php and page.php file.



<? php get_sidebar(); ?>



Replace it with the following code snippet.



<? php $sidebar = get_post_meta($post->ID, "sidebar", true);

get_sidebar($sidebar);

?>



When writing a post, create new custom fields named sidebar. In the value section, mention the name of the sidebar you want to display so if you built two different sidebar files (e.g. sidebar-category.php and sidebar-promotion.php) and wanted to show the sidebar-category.php, you’d use the key as “sidebar” and value as “sidebar-category“.

33. Define how individual posts should be displayed on the homepage

Most of the themes display all of your posts in the same way on the homepage. That is, on the homepage, either it shows excerpts only or it shows the full post. However, you may not want to display all of your posts in the same way on the homepage.



Find the loop in your index.php file and replace it with the following so that you can define how each post should be displayed.

<?php if (have_posts()) :

while (have_posts()) : the_post();

$customField = get_post_custom_values("full");

if (isset($customField[0])) {

//Custom field is set, display a full post

the_title();

the_content();

} else {

// No custom field set, let's display an excerpt

the_title();

the_excerpt();

endwhile;

endif;

?>

In the above WordPress tips, by default excerpts are displayed on the homepage. To show posts fully on the homepage, create a custom field 'full' from the post editor and give it any value.

Usually, titles of blog posts in the homepage are linked to the original post URL.

However, if the sole purpose of publishing a particular blog post is to share a particular external link, you may not want to entice the users to open up your post. Instead, the users can visit the external link by simply clicking the blog post title from the homepage itself. Add the following code to functions.php file.

function print_post_title() {

global $post;

$thePostID = $post->ID;

$post_id = get_post($thePostID);

$title = $post_id->post_title;

$perm = get_permalink($post_id);

$post_keys = array(); $post_val = array();

$post_keys = get_post_custom_keys($thePostID);

if (!empty($post_keys)) {

foreach ($post_keys as $pkey) {

if ($pkey=='url1' || $pkey=='title_url' || $pkey=='url_title') {

$post_val = get_post_custom_values($pkey);

}

}

if (empty($post_val)) {

$link = $perm;

} else {

$link = $post_val[0];

}

} else {

$link = $perm;

}

echo '<h2><a href="'.$link.'" rel="bookmark" title="'.$title.'">'.$title.'</a></h2>';

}

Then, open your index.php and find the following code

<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>

Replace it with the below code and you’re done!

<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php print_post_title() ?></a></h2>

35. Add featured image support for your theme

‘Featured images’ is one of the most popular features of WordPress.

It is supported in most of the themes available today. However, if your theme doesn’t support this feature, you can add support for this feature by tweaking the theme’s functions file

add_theme_support( 'post-thumbnails' );

36. Custom CSS for individual posts

You may need to use custom stylesheet for individual posts. Insert the following code in header.php between <head>and </head>

<?php if (is_single()) {

$customstyle = get_post_meta($post->ID, 'customstyle', true);

if (!empty($customstyle)) { ?>

<style type="text/css">

<?php echo $customstyle; ?>

<style>

<?php }

} ?>

Then, add a custom field in the posts with the name customstyle and add the CSS code in there.

Add the following changes anywhere in your theme where you want to display the 5 most recent comments. As with other WordPress tips we've mentioned here, you can change the number 5 to show more or less comments as needed.

<?php

$query = "SELECT * from $wpdb->comments WHERE comment_approved= '1'

ORDER BY comment_date DESC LIMIT 0 ,5";

$comments = $wpdb->get_results($query);

if ($comments) {

echo '<ul>';

foreach ($comments as $comment) {

$url = '<a href="'. get_permalink($comment->comment_post_ID).'#comment-'.$comment->comment_ID .'" title="'.$comment->comment_author .' | '.get_the_title($comment->comment_post_ID).'">';

echo '<li>';

echo '<div class="img">';

echo $url;

echo get_avatar( $comment->comment_author_email, $img_w);

echo '</a></div>';

echo '<div class="txt">Par: ';

echo $url;

echo $comment->comment_author;

echo '</a></div>';

echo '</li>';

}

echo '</ul>';

}

?>

Often, you might want to edit some published comments.

By default, if you are logged in to your site, on top of every comment you published you can see a link where you can click to edit the comment. Additionally, how about marking a comment as spam or even delete it from your blog post itself?

This is one of those WordPress tricks which can really help you maintain your website easier and faster, because you're doing everything from the frontend.

Add the below code to functions file.

function delete_comment_link($id) {

if (current_user_can('edit_post')) {

echo '| <a href="'.admin_url("comment.php?action=cdc&c=$id").'">del</a> ';

echo '| <a href="'.admin_url("comment.php?action=cdc&dt=spam&c=$id").'">spam</a>';

}

}

Then, add the below code snippet to comments.php file.



delete_comment_link(get_comment_ID());

Bonus Tip

Have you ever had the needed to create great-looking popups to increase conversions to your email list? We found the best WordPress popup plugin to help you increase conversions.

Now that we've mentioned a bunch of tips associated with the display, we're going to now focus on some WordPress community tricks. The following WordPress tips tricks and tweaks are useful for multi-author/community-powered website.

39. Create custom user roles

WordPress provides the following user roles by default- administrator, editor, author, contributor, and subscriber. However, at times, you may need to assign some customized user roles.



For example, if you want to provide an option to edit the pages only to a new user, here’s how to do it:

Add the following lines to the functions file. You can change the various functionality availability by setting the appropriate setting to true or false.

// Add a custom user role

$result = add_role( 'new', __(

'New' ),

array(

'read' => true, // true allows this capability

'edit_posts' => false, // Allows user to edit their own posts

'edit_pages' => true, // Allows user to edit pages

'edit_others_posts' => false, // Allows user to edit others posts not just their own

'create_posts' => false, // Allows user to create new posts

'manage_categories' => false, // Allows user to manage post categories

'publish_posts' => false, // Allows the user to publish, otherwise posts stays in draft mode

'edit_themes' => false, // false denies this capability. User can’t edit your theme

'install_plugins' => false, // User can't add new plugins

'update_plugin' => false, // User can’t update any plugins

'update_core' => false // user can't perform core updates

)

);

40. Disable admin bar except for admin

Often for membership/community site, the WordPress admin bar would not be customized for the end users. In such cases, you may want to disable admin bar access to other users except admin.

Add the following snippet to the functions file to disable access to non-administrator users.

add_action('after_setup_theme', 'remove_admin_bar');

function remove_admin_bar() {

if (!current_user_can('administrator') && !is_admin()) {

show_admin_bar(false);

}

}

41. Disable admin bar access to all users

If you want to disable access to admin bar for all the users including the administrator, add the following to the functions file.

show_admin_bar(false);

42. Automatically add new users to BuddyPress group

This trick is for the BuddyPress plugin, which is the most popular niche social network plugin for WordPress. By this tweak, you can automatically add all the newly joined BuddyPress members to a specific group.

function automatic_group_membership( $user_id ) {

if( !$user_id ) return false;

groups_accept_invite( $user_id, <# group ID #> );

}

add_action( 'bp_core_activated_user', 'automatic_group_membership' );

43. Add author bio wherever you want

Simply add the following lines to the single.php file to show author bio in your preferred location.

<div id="author-bio">

<h3>About <?php the_author(); ?></h3>

<?php echo get_avatar( get_the_author_email(), '70' ); ?>

<?php the_author_description(); ?>

</div>

In addition, add the following code to the CSS file to make the author bio look better



#author-bio { border-top: 1px dotted #cccccc; padding: 15px 0; }

#author-bio h3 { font-size: 16px; margin: 0 0 5px 0; }

#author-bio img { float: left; padding: 2px; border: 1px solid #cccccc; margin: 5px 15px 0 0; }

44. Replace "Howdy" message from the dashboard

Sometimes you may want to change the “Howdy” message from your WordPress dashboard and customize it according to your wish. Add the following code to the functions file.

function replace_howdy( $wp_admin_bar ) {

$my_account=$wp_admin_bar->get_node('my-account');

$newtitle = str_replace( 'Howdy,', 'Logged in as', $my_account->title );

$wp_admin_bar->add_node( array(

'id' => 'my-account',

'title' => $newtitle,

) );

}

add_filter( 'admin_bar_menu', 'replace_howdy',25 );

All that you needed is to insert the new message as the 2nd element within the $newtitle array, and you're done. As usual for such WordPress tricks, change the value of the text to whatever you want to display!

45. Make featured image required for publishing a blog post

Tweak your functions file to make featured images mandatory for publishing blog posts.

add_action('save_post', 'wpds_check_thumbnail');

add_action('admin_notices', 'wpds_thumbnail_error');

function wpds_check_thumbnail( $post_id ) {

// change to any custom post type

if( get_post_type($post_id) != 'post' )

return;

if ( ! has_post_thumbnail( $post_id ) ) {

// set a transient to show the users an admin message

set_transient( "has_post_thumbnail", "no" );

// unhook this function so it doesn't loop infinitely

remove_action('save_post', 'wpds_check_thumbnail');

// update the post set it to draft

wp_update_post(array('ID' => $post_id, 'post_status' => 'draft'));

add_action('save_post', 'wpds_check_thumbnail');

} else {

delete_transient( "has_post_thumbnail" );

}

}

function wpds_thumbnail_error() {

// check if the transient is set, and display the error message

if ( get_transient( "has_post_thumbnail" ) == "no" ) {

echo "<div id='message' class='error'><p><strong>You must add a Featured Image before publishing this. Don't panic, your post is saved.</strong></p></div>";

delete_transient( "has_post_thumbnail" );

}

}

46. Add confirmation box when publishing pages & posts

This trick avoids publishing an incomplete post by accident. You can add the following snippet, as usual to the functions file.

add_action( 'admin_print_footer_scripts', 'sr_publish_molly_guard' );

function sr_publish_molly_guard() {

echo "

<script>

jQuery(document).ready(function($){

$('#publishing-action input[name=\"publish\"]').click(function() {

if(confirm('Are you sure you want to publish this?')) {

return true;

} else {

$('#publishing-action .spinner').hide();

$('#publishing-action img').hide();

$(this).removeClass('button-primary-disabled');

return false;

}

});

});

</script>

";

}

47. Redirect to custom page after registration

Paste the below lines to the functions to redirect users to a custom page after registration

function __my_registration_redirect(){

return home_url( '/my-page' );

}

add_filter( 'registration_redirect', '__my_registration_redirect' );

48. Add social profile information on the user profile page

By default, the user profile page in the dashboard has fields to add the contact info including AIM, Yahoo IM, Jabber/Google Talk, etc. Open the functions file and add the following snippet to add more social media fields in the user profile page.

function my_new_contactmethods( $contactmethods ) {

// Add Twitter

$contactmethods['twitter'] = 'Twitter';

//add Facebook

$contactmethods['facebook'] = 'Facebook';

return $contactmethods;

}

add_filter('user_contactmethods','my_new_contactmethods',10,1);

You can use the following code in author.php file to display it.



echo $curauth->twitter;



49. List all authors of your blog in a page

Add the following code where you want to display the list of all authors of your blog.

<ul>

<?php wp_list_authors('exclude_admin=0&optioncount=1&show_fullname=1&hide_empty=1'); ?>

</ul>

50. Display guest author’s name via custom fields

Most guest authors are onetime publishers, especially if you are taking guest posts on your site. So there is no point in creating a separate profile for them. Rather, add the following code to single.php where you’d like to display the author name. You can display all guest posts using this description.

<?php $author = get_post_meta($post->ID, "guest-author", true);

if ($author != "") {

echo $author;

} else {

the_author();

} ?>

Once done, create a custom field named guest-author and type your custom title as a value.

Given that you're going to be pulling in visitors, the following are several WordPress analytics tricks.

51. Insert Google Analytics code

Find the <body> tag inside the header.php file and insert the Google Analytics code right after. Super easy, but a very essential WordPress tip!

52. A/B test using Google Analytics

A/B testing different versions of your page will help you improve the conversion rate. Here’s how to do A/B test on your site using Google Analytics.

Make sure you’ve installed Google Analytics on your site using the above tip. In your Google Analytics account, click the behavior tab>> click experiments>> choose your experiment objectives and configure your experiment. Learn more about this step from the official site. Find the page id of your original page, and replace $page_id with the id of your original page to the below code. Then, get the experiment code from Analytics and add it to the below code

<? php if (is_page($page_id)) :

?>

Add Content

Experiment Code Here

<? php endif; ?>

4. Save this code to the header file and click next>>start experiment in Google Analytics.

53. Track file downloads using Google Analytics

Using Google Analytics’ event tracking functionality, you can track file downloads without a plugin. See the below example code for event tracking.

<a onclick="_gaq.push(['_trackEvent','Download','PDF',this.href]);" href="https://cdn.collectiveray.com/ebook.pdf" target="_blank">Download ebooks</a>

We have a full post on how to do this, either using Analytics or other plugins here.

And of course, once you have visitors, you're going to want to monetize that traffic, so here are a good bunch of monetization tips.

So here are WordPress tips tricks and tweaks for monetization of your website

Monetization is very important for most blogs, so why don't you follow these recommendations for making some extra cash off your WP site.

54. Display AdSense ads only to search engine visitors

If you look at the total ad clicks you receive on your website, you'll find that search engine visitors are more likely to click the contextual ads like AdSense than any other visitor.

So restricting your ads to display only to the visitors that come from search engines can help you increase the CTR of your ad.

To display ads only to search engine visitors, add the following code you to your functions.php file. You can update the $SE string to any more referral traffic you want, rather than just search engines.

You can also add other search engines apart from the ones listed below:

$ref = $_SERVER['HTTP_REFERER'];

$SE = array('/search?', 'images.google.', 'web.info.com', 'search.', 'del.icio.us/search', 'soso.com', '/search/', '.yahoo.');

foreach ($SE as $source) {

if (strpos($ref,$source)!==false) {

setcookie("sevisitor", 1, time()+3600, "/", ".yourdomain.com");

$sevisitor=true;

}

}

function visits_from_searchengine(){

global $sevisitor;

if ($sevisitor==true || $_COOKIE["sevisitor"]==1) {

return true;

}

return false;

}

Make sure you change yourdomain.com to your domain. Then, add the following code snippet to single.php file.

<?php if (function_exists('visits_from_searchengine')) {

if (visits_from_searchengine()) { ?>

YOUR CODE HERE

<? php } } ?>

Don’t forget to add your AdSense code by replacing YOUR CODE HERE.

55. Hide ads for single posts

If you are displaying advertisements on every blog post and want to hide ads for a certain post, just add the following code snippet to your single.php file. Make sure you replace xx with the post id and insert your ad code to the below code snippet.



if(get_the_ID() != xx) {

Your ad code here

}

56. Embed ad inside the excerpts of first blog post

On the homepage, you can place an advertisement inside the excerpts of your first blog post. This is a bit aggressive so handle with care, make sure you only have one advert above the fold, because this WordPress tip can land you in hot water with Google and can result in a penalty if it comes at the expense of the user experience.



Open index.php file and find <?php if (have_posts())

Add the following line above it:

<?php $count = 1; ?>

Then, find the code that starts with

<?php the_content

Add the following code after the closing tag, ?>

<?php if ($count == 1) : ?>

AD CODE

<?php endif; $count++; ?>

Make sure you replace AD CODE with your advertisement code.

57. Wrap ads in post wherever you want

In functions.php file, add the below code snippet. In addition, make sure you insert your ad codes inside it.

function googleadsense($content){

$adsensecode = 'Your Ad Codes Here';

$pattern = '<!-googlead->';

$content = str_replace($pattern, $adsensecode, $content);

return $content;

}

add_filter('the_content', 'googleadsense');

Insert <!-googlead-> in your posts and pages wherever you want to display the ad.

Execute the below SQL query against your database to export all the user submitted email addresses with no duplicates. This can be helpful for building your email list.

SELECT DISTINCT comment_author_email FROM wp_comments;

Following the implementation of GDPR, this needs to be exclusively specified and agreed to as part of your privacy policy. You also need to double opt-in and users which are added to your mailing list in this way.

59. Display ads using shortcodes

Insert the shortcode, [adsense] anywhere inside the posts and pages content where you want the ads to be displayed. Just add the below-given lines to your functions.php file.

function showads () {

return '

ADS CODE HERE

';

}

add_shortcode(' adsense ', ' showads ');

Setting an expiration date for your post is a good idea especially if you are offering limited time discount for your products or running a contest.

Just replace the WP loop with the following code.

<?php

if (have_posts()) :

while (have_posts()) : the_post(); ?>

$expirationtime = get_post_custom_values('expiration');

if (is_array($expirationtime)) {

$expirestring = implode($expirationtime);

}

$secondsbetween = strtotime($expirestring)-time();

if ( $secondsbetween > 0 ) {

// For example…

the_title();

the_excerpt();

}

endwhile;

endif;

?>

In the custom fields, make sure you choose key ‘expiration’ and the following date format: mm/dd/yyyy 00:00:00. This WordPress trick doesn’t remove or unpublish the post but it excludes the post from being displayed in the loop. For SEO purposes, you'll want to unpublish this post if it no longer relevant, because it will still appear in such files as the sitemap.xml of your site.

61. Add promotional content in homepage above the articles

In index.php file, find the following code: <div class="content-loop"> . Add your promotional content above it, whether it is email newsletter form, advertisement, etc.

An even more important aspect of your blog is security. The following are WordPress security tricks you need to put in place asap.

62. Limit access to login page for specific IP addresses

If your IP addresses don’t change often, you can limit access to WordPress login page to that specific IP address only.



See the following code, replace the 128\.128\.128\.128 with your own IP address (include the \ to escape the full stop in the address) and add the code to .htaccess file.



As with such WordPress tips, please make sure you have backups, just in case you make a small mistake and need to revert to the previous version.

ErrorDocument 401 /path-to-your-site/index.php?error=404

ErrorDocument 403 /path-to-your-site/index.php?error=404

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteCond %{REQUEST_URI} ^(.*)?wp-login\.php(.*)$ [OR]

RewriteCond %{REQUEST_URI} ^(.*)?wp-admin$

RewriteCond %{REMOTE_ADDR} !^128\.128\.128\.128

RewriteRule ^(.*)$ - [R=403,L]

</IfModule>

63. Block specific ip address

Add the following lines to the .htaccess file to deny certain ip addresses from accessing your site.

# allow all except those indicated here

<Files *>

order allow,deny

allow from all

deny from xxx.xxx.xxx.xxx

</Files>

64. Create a manual backup of your database

Log in to phpMyAdmin, select the WP database you want to backup. Click export, choose a compression method and click execute. When your browser prompts you to download the backup, click yes.

65. Use SSL mode for log in

If you have an SSL certificate installed on your server, you can force your WP installation to use SSL mode for secure user log in.

For that, add the below code to wp-config.php file.

define('FORCE_SSL_LOGIN', true);

Incidentally, if you want to avoid all of the hassle associated with getting an SSL yourself, our host, InMotion, actually supports SSL hosting, via their InMotion shared accounts. Read our full review here: https://www.collectiveray.com/inmotion-hosting-review

66. Disable/Change log error message

Tweak your functions.php by adding the following snippet to disable WordPress login error message.

function no_wordpress_errors(){

return 'GET OFF MY WEBSITE !! RIGHT NOW !!';

}

add_filter( 'login_errors', 'no_wordpress_errors' );

67. Restrict access to wp-includes file

Again, add the code to .htaccess file to disable the access to wp-includes.php

# Block wp-includes folder and files

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /

RewriteRule ^wp-admin/includes/ - [F,L]

RewriteRule !^wp-includes/ - [S=3]

RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]

RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]

RewriteRule ^wp-includes/theme-compat/ - [F,L]

</IfModule>

68. Template file editing

Any WordPress user with administrator access can edit templates by navigating to Appearance > Editor.

You can disable template file editing by adding the following line of code to wp-config.php



define( ‘DISALLOW_FILE_EDIT’, true );

69. Hide version number

Each WordPress version will have a few vulnerabilities. If a hacker manages to identify which version of WordPress you’re using, he can exploit it to gain control of your website through the known vulnerabilities.

Inserting below code to your functions.php will hide the WP version number, which will be an added protection for your site.

remove_action('wp_head','wp_generator');

70. Restore your WP database

Log in phpMyAdmin, select your WordPress database, click the import button, click browse and select the database you would like to restore from your hard disk. Then, click the execute button.

71. Disable direct access to directories

If you want to disable external access to the root directory, add the following to .htaccess file



# Disable directory browsing

Options All -Indexes

72. Disable access to specific file types

Create a new .htaccess file, add the following code and upload the file inside wp-content folder.

# Disable access to all file types except the following

Order deny,allow

Deny from all

<Files ~ ".(xml|css|js|jpe?g|png|gif|pdf|docx|rtf|odf|zip|rar)$">

Allow from all

</Files>

This will disable access to all file types except the mentioned files in the code.

73. Deny access to all .htaccess files

Add the code to .htaccess to deny access to all of your .htaccess files

# Deny access to all .htaccess files

<files ~ "^.*\.([Hh][Tt][Aa])">

order allow,deny

deny from all

satisfy all

</files>

74. See recently modified files

If you have SSH access to your server, sign in and run the command below to see the recently modified files. This command comes in handy especially if you are suspecting vulnerable access to your server without your consent.

The below command will show changes made in the last 2 days in the specified directory.

find /home/yourdirectory/yoursite/ - mtime -2 -ls

75. Manually reset your password

Log in to phpMyAdmin, select the website database, click SQL and paste the following command.

UPDATE `wp_users` SET `user_pass` = MD5( 'PASSWORD ') WHERE `wp_users`.`user_login` =`admin` LIMIT 1;

Note: You need to change the ‘admin’ to your actual username and PASSWORD to your preferred password.

76. Deactivate all plugins when not able to access the dashboard

Often, you may need to deactivate all plugins for troubleshooting. However, if for some unfortunate reason you are not able to log in to your dashboard, you can deactivate all plugins from FTP.



Go to wp-content/ directory and change the folder name from plugins to something else, such as wp-content-backup.

77. Show all active plugins

For maintenance purposes, you might want to get the list of active plugins on a specific WordPress install. Paste the following code to functions.php file, and you'll start seeing active plugins list on your dashboard.

add_action('wp_dashboard_setup','wpse_54742_wp_dashboard_setup');

function wpse_54742_wp_dashboard_setup(){

wp_add_dashboard_widget('wpse_54742_active_site_plugins', __('Active Plugins'),'wpse_54742_active_site_plugins');} function wpse_54742_active_site_plugins(){

$the_plugs = get_option('active_plugins');

echo '<ul>';

foreach($the_plugs as $key => $value){

$string = explode('/',$value);// Folder name will be displayed

echo '<li>'.$string[0].'</li>'; }

echo '</ul>';}

Instead of marking comments as spam each time, you can block the spammers outright from publishing comments on your blog. The below code will look for HTTP referrer and automatically blocks the comment if the referrer is not valid.

Add the below code in the functions.php file.

function check_referrer() {

if (!isset($_SERVER['HTTP_REFERER']) || $_SERVER['HTTP_REFERER'] == “”) {

wp_die( __('Please enable referrers in your browser, or, if you're a spammer, bugger off!') );

}

}

add_action('check_comment_flood', 'check_referrer');

And of course, besides humans, we want search engines to love our website. So next on our list are WordPress SEO tips and tricks.

If your content is not time-sensitive, make sure you avoid displaying WordPress post date stamp on SERP, which will increase the CTR of your posts that display on SERP.

Go to single.php file and find something like this

<? php the_time('F jS, Y') ?>

Replace it with the following code

<script language="javascript" type="text/javascript">document.write("<?php the_time('F jS, Y') ?>");</script>

80. Prevent image hotlinking

Protecting your images from hotlinking will help you save lots of bandwidth by preventing other sites from displaying your images.

Simply go to .htaccess file and add the below code. Make sure you replace the ‘your-domain-name’ part with your actual domain name.

RewriteEngine on

RewriteCond %{HTTP_REFERER} !^$

RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?your-domain-name [NC]

RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]

81. Restrict bots access

By preventing vulnerable bots from accessing your website, you can tighten the security of your WordPress blog. Copy the following code to .htaccess file.

SetEnvIfNoCase User-Agent ^$ keep_out

SetEnvIfNoCase User-Agent (pycurl|casper|cmsworldmap|diavol|dotbot) keep_out

SetEnvIfNoCase User-Agent (flicky|ia_archiver|jakarta|kmccrew) keep_out

SetEnvIfNoCase User-Agent (purebot|comodo|feedfinder|planetwork) keep_out

Order Allow,Deny

Allow from all

Deny from env=keep_out

82. Disable self pingbacks

Add the following code to your functions.php file to disable the self pingbacks.

// Disable self pingbacks in WordPress

function disable_self_trackback( &$links ) {

foreach ( $links as $l => $link )

if ( 0 === strpos( $link, get_option( 'home' ) ) )

unset($links[$l]);

}

add_action( 'pre_ping', 'disable_self_trackback' );

83. Block directories using robots.txt

Restrict search engines from crawling to the root directory by adding the code snippet below to robots.txt file.

User-agent: *

Disallow: /cgi-bin/

Disallow: /wp-admin/

Disallow: /wp-includes/

Disallow: /xmlrpc.php

Disallow: /wp-content/plugins/

Disallow: /wp-content/cache/

Disallow: /wp-content/themes/

Disallow: /trackback/

Disallow: /feed/

Disallow: /comments/

Disallow: /category/

Disallow: /trackback/

Disallow: /feed/

Disallow: /comments/

Disallow: /*?

Allow: /wp-content/uploads/

84. Redirect traffic from www to non-www

301 redirect all the traffic from www to non-www version by adding the following code to the .htaccess file.

# Redirect Non-WWW to WWW

RewriteEngine on

RewriteCond %{HTTP_HOST} ^yourwebsite\.com

RewriteRule ^(.*)$ https://www.yourwebsite.com/$1 [R=301,L]

# END Redirect Non-WWW to WWW

# BEGIN WordPress

RewriteEngine On

RewriteBase /

RewriteRule ^index\.php$ – [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

# END WordPress

Remember to replace yourwebsite with your website URL. Additionally, in the general settings option, you will need to add WWW to the [WordPress Address (URL)]and [Site Address (URL)]

85. Show the number of search results found

Display the number of search results found in your WordPress search results page by adding the following line of code to your search.php file.

<h2 class="pagetitle">Search Result for <?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('<span class="search-terms">'); echo $key; _e('</span>'); _e(' — '); echo $count . ' '; _e('articles'); wp_reset_query(); ?></h2>

86. Exclude categories from search

When a user does a search on your site, sometimes you may want not to show search results from a particular category that contains promotional contents, portfolio items, etc. Simply add the following code to functions.php file to exclude specific categories from search.

function SearchFilter($query) {

if ( $query->is_search && ! is_admin() ) {

$query->set('cat','8,15');

}

return $query;

}

add_filter('pre_get_posts','SearchFilter');

87. Exclude pages from search

If you want to avoid displaying particular pages as the search results, add the following code snippet to functions.php file.

function modify_search_filter($query) {

if ($query->is_search) {

$query->set('post_type', 'post');

}

return $query;

}

add_filter('pre_get_posts','modify_search_filter');

88. Delete all pingbacks

Execute the below SQL query against your database to delete all the pingbacks you received. As usual, these WordPress tips where we delete stuff from the database can cause irreperable harm to your website. Take backups!



DELETE FROM wp_comments WHERE comment_type = 'pingback';

Spammers used to submit tons of HTML links while commenting, which can have negative impact in bringing organic traffic to your website. Simply open functions.php and insert the following code to disable HTML elements in comments.

// This will occur when the comment is posted

function plc_comment_post( $incoming_comment ) {

// convert everything in a comment to display literally

$incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']);

// the one exception is single quotes, which cannot be #039; because WordPress marks it as spam

$incoming_comment['comment_content'] = str_replace( "'", ''', $incoming_comment['comment_content'] );

return( $incoming_comment );

}

// This will occur before a comment is displayed

function plc_comment_display( $comment_to_display ) {

// Put the single quotes back in

$comment_to_display = str_replace( ''', "'", $comment_to_display );

return $comment_to_display;

And who else besides search engines is important to our websites? Social networks of course! Here are WordPress social network tricks.

Of course, your blog would be nothing if it's not social today - here's a few more WordPress tips tricks and tweaks for socialing your blog.

Replace your existing code in your comments.php file with the below given code to enable Google+ comments on your blog posts.

<script src="https://apis.google.com/js/plusone.js">

</script>

<div class="g-comments"

data-href="<?php the_permalink(); ?>"

data-width="800"

data-first_party_property="BLOGGER"

data-view_type="FILTERED_POSTMOD">

</div>

If you’re using Twenty Fourteen theme, here’s how your comments.php file will look like after the modification.

<?php

/**

* The template for displaying Comments

*

* The area of the page that contains comments and the comment form.

*

* @package WordPress

* @subpackage Twenty_Fourteen

* @since Twenty Fourteen 1.0

*/

/*

* If the current post is protected by a password and the visitor has not yet

* entered the password we will return early without loading the comments.

*/

if ( post_password_required() ) {

return;

}

<script src="https://apis.google.com/js/plusone.js">

</script>

<div class="g-comments"

data-href="<?php the_permalink(); ?>"

data-width="800"

data-first_party_property="BLOGGER"

data-view_type="FILTERED_POSTMOD">

</div>

91. Add pinterest “pin it” button

Add the following code to the footer.php file.

<script type="text/javascript">

(function() {

window.PinIt = window.PinIt || { loaded:false };

if (window.PinIt.loaded) return;

window.PinIt.loaded = true;

function async_load(){

var s = document.createElement("script");

s.type = "text/javascript";

s.async = true;

s.src = "https://assets.pinterest.com/js/pinit.js";

var x = document.getElementsByTagName("script")[0];

x.parentNode.insertBefore(s, x);

}

if (window.attachEvent)

window.attachEvent("onload", async_load);

else

window.addEventListener("load", async_load, false);

})();

</script>

Then, add following code to your single.php file

<?php $pinterestimage = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); ?>

<a href="https://pinterest.com/pin/create/button/?url=<?php echo urlencode(get_permalink($post->ID)); ?>&media=<?php echo $pinterestimage[0]; ?>&description=<?php the_title(); ?>" class="pin-it-button" count-layout="vertical">Pin It</a>

92. Create send to Twitter button

With one click, your readers can share your blog post URL to Twitter.



Simply add the following code snippet anywhere on your posts.

<a href="https://twitter.com/home?status=Currently reading <? php the_permalink(); ?>" title="Click to send this page to Twitter!" target="_blank">Share on Twitter</a>

Integrating Facebook Comments to your blog posts will offer an easy way for your readers to comment on your blog as well as share it on Facebook.

Read the ultimate guide to display Facebook Comments on your blog.

94. Show selective tweets

If yours is a personal twitter account, you might not want to show every tweet to your blog readers. In such cases, you can display only selective tweets to your blog readers with a certain keyword or hashtag.



Go to Twitter Widgets>> click the button ‘create new’ >> click the ‘search’ tab



In the search query box, enter from:dartcreations webdesign



Replace the dartcreations with your twitter handle and webdesign with your preferred query. Save your widget and copy it to your widgets section of your WordPress site.

95. Redirect feeds to FeedBurner feeds

Add the following code to .htaccess for turning WP feeds to FeedBurner feeds.

# temp redirect wordpress content feeds to feedburner

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteCond %{HTTP_USER_AGENT} !FeedBurner [NC]

RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]

RewriteRule ^feed/?([_0-9a-z-]+)?/?$ https://feeds.feedburner.com/yourfeed [R=302,NC,L]

</IfModule>

Make sure that you customize the above code with your FeedBurner feed before saving.

96. Category-specific RSS feeds

It is a good idea to offer your readers to subscribe to a particular category of your blog especially if you cover a wide range of categories on your blog.

Simply add /feed to the end of the category URL.

97. Delay posting to RSS feeds

When you publish a blog post, immediately it will send your subscribers notification about the new post via RSS feeds. You can delay posting to RSS feeds for an hour. This can be useful especially in case if you forget to check for broken links or typos before publishing your posts.

function Delay_RSS_After_Publish($where) {

global $wpdb;

if (is_feed()) {

$now = gmdate('Y-m-d H:i:s');

$wait = '60';

$device = 'MINUTE';

$where.=" AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";

}

return $where;

}

add_filter('posts_where', 'Delay_RSS_After_Publish');

98. Social media sharing buttons

Add the following code to single.php file to create social media sharing buttons to your post.

<ul class="socialwrap">

<li><a href="https://twitter.com/home?status=Reading: <?php the_title(); ?> – <?php echo get_bloginfo('url')."/?p=".$post->ID; ?>" title="Click to send this page to Twitter!" target="_blank">Share to Twitter</a></li>

<li><a href="https://digg.com/submit?phase=2&url=<?php the_permalink() ?>" rel="nofollow">Add to digg</a></li>

<li><a href="https://www.stumbleupon.com/submit?url=<?php the_permalink() ?>&title=<?php the_title(); ?>" rel="nofollow">Add to Stumbleupon"</a>></li>

<li><a href="https://www.facebook.com/sharer.php?u=<?php the_permalink(); ?>&t=<?php the_title(); ?>" target="blank">Share to Facebook</a></li>

</ul>

99. Display Feedburner count as text

Get rid of the annoying Feedburner button and display the subscribers count as text.

Just copy and paste the following code to your sidebar.php file.

<?php

//get cool feedburner count

$whaturl="https://api.feedburner.com/awareness/1.0/GetFeedData?uri=your feedburner id";

//Initialize the Curl session

$ch = curl_init();

//Set curl to return the data instead of printing it to the browser.

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//Set the URL

curl_setopt($ch, CURLOPT_URL, $whaturl);

//Execute the fetch

$data = curl_exec($ch);

//Close the connection

curl_close($ch);

$xml = new SimpleXMLElement($data);

$fb = $xml->feed->entry['circulation'];

echo $fb;

//end get cool feedburner count

?>

100. Display Twitter counter as text

If you are among those who hate displaying Twitter counter as button, this tweak is for you. Create a file called twitter.php and paste the following code in that file.

<?php

$tw = get_option("twitterfollowerscount");

if ($tw['lastcheck'] < ( mktime() – 3600 ) )

{

$xml=file_get_contents('https://twitter.com/users/show.xml?screen_name=twitterhandle');

if (preg_match('/followers_count>(.*)</',$xml,$match)!=0) {

$tw['count'] = $match[1];

}

$tw['lastcheck'] = mktime();

update_option("twitterfollowerscount",$tw);

}

echo $tw['count'];

?>

Make sure you replace your twitterhandle with your twitter handle. Then, replace the below code to your sidebar.php file.

<?php include("twitter.php"); ?>

Insert the following code to your post editor where you want to add the retweet button. Make sure you replace the 'TWEET-ID' with your the original tweet id.

<a href="https://twitter.com/intent/retweet?tweet_id=TWEET-ID" class="retweet" style="display:inline-block;font-family:georgia,serif;font-size:12px;color:#000;text-decoration:none;padding:1px 5px;border:1px solid #ccc;border-radius:3px;background-color:#ddd;background:linear-gradient(to bottom, #f6f6f6, #ddd)">Retweet</a> <style>.retweet:hover{opacity:0.9}</style> <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>

Wrapping Up

Of course, we've included these 101 WordPress tips tricks and tweaks in this article because we believe these are some of the best optimizations for WordPress which you can implement quickly and easily without having to hire a developer.

These are small changes in the code which you can quickly achieve yourself without risking breaking your website or your WordPress template ;-)

Need help getting stuff done? Try these top-rated gigs on Fiverr! (from $5)

Click here to find experts on WordPress.

Click here to create a full WordPress website.

About the Author Author: David Attard Website: https://www.linkedin.com/in/dattard/ David Attard David has been working in or around the online / digital industry for the last 18 years. He has vast experience in the software and web design industries using WordPress, Joomla and niches surrounding them. As a digital consultant, his focus is on helping businesses get a competitive advantage using a combination of their website and digital platforms available today.