automatically delete spam comments in wordpress

WordPress Spam comments is big issue. I am getting daily 5k spam comments daily. we automated task of  deleting spam comments automatically. Daily going to comments dashboard and deleting spam comments is really boring task. WordPress Akismat wordpress plugin does good job of finding spam comments.

automatically delete spam comments in wordpress
automatically delete spam comments in wordpress

 

How to automatically delete spam comments in wordpress?

I am using Akismat wordpress plugin for my all wordpress blogs. It does good job of finding spam comments. Due to spam comments. comment-meta table becoming big and causing mysql resource issues. So cleaning comments table became necessary. so we used following hook in wordpress theme code.


function auto_delete_spam_comments() {
$in_progress = (bool) get_site_option( 'spamcomment_delete_in_progress' );
if ( ! $in_progress ) {
global $wpdb;
update_site_option( 'spamcomment_delete_in_progress', '1' );
// 4980
$next = (int) get_site_option( 'spamcomments_delete_next_blog' );
if ( empty( $next ) ) {
$next = 1;
}

if ( $next > 3000 ) {
return;
}
switch_to_blog( $next );

$spams = $wpdb->get_col( "SELECT comment_id FROM {$wpdb->comments} WHERE comment_approved = 'spam' LIMIT 10" );
if ( empty( $spams ) ) {
$next++;
update_site_option( 'spamcomments_delete_next_blog', $next );
} else {
foreach ( $spams as $spam ) {
wp_delete_comment( $spam, true );
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->commentmeta} WHERE comment_id = %d", $spam ) );
}
}
// reclaim disk space
$wpdb->query( "OPTIMIZE TABLE {$wpdb->comments}" );
$wpdb->query( "OPTIMIZE TABLE {$wpdb->commentmeta}" );
restore_current_blog();
delete_site_option( 'spamcomment_delete_in_progress' );
}
}
register_shutdown_function( 'auto_delete_spam_comments' );

Notes:
The number of blogs is hardcoded (3000)
Add above code in functions.php file.

If you want WordPress to automatically empty my spam comments after 1 day. Just add this to wp-config.php. Following code will automatically Empty Your WordPress Trash

/**
 * Delete Spam Comments.
 */
define( 'EMPTY_TRASH_DAYS', 1 );

To disable trash set the number of days to zero. Note that WordPress will not ask for confirmation when someone clicks on “Delete Permanently”.

define( 'EMPTY_TRASH_DAYS', 0 ); // Zero days

If you want more information Automatically empty wordpress Trash comments and posts and How to make empty wordpress trash automatically

add nofollow and _blank target to wordpress author bio

wordpress seo tips, Here in this article, we shown how to add nofollow and _blank target to wordpress author bio (Biographical Info) section. I am writing blog since 2008. I written on many topics and many blogs. I always accept article from guest author. Some of guest author want to publish their company or personal information in author bio section.

Some months before google changed search engine algorithm. Google look in blog, how many direct out links are used in site. I have many author articles and bio section published in our blogs. We decided to add Nofollow and new tab link attribute in for author bio section.

add nofollow and _blank target to wordpress author bio

If you manually try to add blank target and nofollow for anchor tag. wordpress removes nofollow and target from author bio section using hook.

add nofollow and _blank target to wordpress author bio
add nofollow and _blank target to wordpress author bio

We used simple str_replace method to modify the author bio section.

We created post-author.php file and added following code in that file.

if ( ! function_exists( 'wpapi_post_author' ) ) {

function wpapi_post_author() {

// Only display for standard posts
global $post;
$post_id = $post->ID;
if ( 'post' !== get_post_type($post_id) ) return;

// Vars
$author = get_the_author();
$author_description = get_the_author_meta( 'description' );
$author_description = str_replace('href','rel="nofollow" target="_blank" href', $author_description);
$author_url = esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) );
$author_avatar = get_avatar( get_the_author_meta( 'user_email' ), apply_filters( 'wpapi_author_bio_avatar_size', 75 ) );

// Only display if author has a description
if ( !$author_description ) return; ?>

<div class="author-info boxed clr">
<h4 class="heading"><span><?php printf( __( 'Written by %s', 'wpapi' ), $author ); ?></span></h4>
<div class="author-info-inner clr">
<?php if ( $author_avatar ) { ?>
<a href="<?php echo $author_url; ?>" rel="author" class="author-avatar">
<?php echo $author_avatar; ?>
</a>
<?php } ?>
<div class="author-description">
<p><?php echo $author_description; ?></p>
</div><!-- .author-description -->
</div><!-- .author-info-inner -->
</div><!-- .author-info -->

<?php } // End function

} // End if

After this we added following line in functions.php file


// Outputs post author bio
require( get_template_directory() .'/functions/post-author.php' );

If you dont want to create separate file than you can directly add above code in functions.php file.

Above code replace all herf with rel=”nofollow” target=”_blank” href tag. When we add any link in author bio section that will replaced.

This really useful for wordpress website SEO because google will trust URLs in author section.

download older version wordpress plugin and themes

Many times we need older version wordpress plugin and themes for old project. Some times due backward compatibility issue we need older version of wordpress plugins which are supported to older wordpress themes.

download older version wordpress plugin and themes

Here we will show you show how to download older version. First go to wordpress plugin directory page.

https://wordpress.org/plugins/

Than search for plugin which you want to download. Go to plugin landing page and click on “Developers” tab. This tab will be last tab on this plugin landing page.

download older version wordpress plugin and themes1
download older version wordpress plugin and themes1

Here we given sample image for download older version.

You will be able to see the all all older versions of that plugin. Under “Other Versions” section we will be able found all older versions.

Why older versions are needed?

Many times we need older version wordpress plugin and themes for clients which are using old wordpress version for their project. Some times we observed, After becoming wordpress plugin so much popular, some plugin developer started the pro version which is paid version. For plugins paid version you need pay. In newer version they removes and limits the functionality to attract the users. You can find all functionality in older wordpress plugin and you do not need pay money for this. You will get all functionality without paying money.

How to check Plugin version Compatibility

For checking older plugin Compatibility with your wordpress version. you need to select your wordpress version in “Compatibility” section and then select older version of  plugin. You will able to see the “Not enough data” or “Works!” status. This is how you can check older plugin is compatible with your wordpress version.

This is very useful when you are working with customers who are using the older wordpress versions for their websites.

turn off wordpress comment email notification

Many times we receive unwanted spam comments email notification from wordpress website. We personally faced comments email notification issue so many times. Many of our clients also faced this issue. WordPress itself given facility to turn off wordpress comment email notification using wordpress admin section. WordPress by default enable the all email types of notification on.

turn off wordpress comment email notification

In this article, We will show you, how to turn off wordpress comment email notification. Using wordpress administration you can switch off wordpress comments email.

Login to WordPress site dashboard. In left side menus,  go to Settings » Discussion. Then look at where it says “Email me whenever” and “Before comments appear” un-check the boxes there.

turn off wordpress comment email notification
turn off wordpress comment email notification

 

Please Use setting as we shown in above picture and save the settings. After this your email notification will be off. Using Other setting “Comments author must have a previously approved comment”. Uncheck that checkbox also. So previous commenter will never publish there comments without your approval.

Why turning off wordpress comment email notification is good?

WordPress send email notification through your server. Many times from sendmail server. If you are getting the huge amount of spam comments than, Your server will try to send email for every spam comment. It will use huge amount memory and server CPU. In that can first stop comment email notification.

Additional Comments setting

On Discussion Page we have “Comment Moderation” section. This setting about spam comments. In textbox you need to add words which you think could be spam related wrods than you can put those words there.

When a comment contains any of these words in its content, name, URL, e-mail, or IP, it will be held in the moderation queue. One word or IP per line. It will match inside words, so “press” will match “WordPress”.

You should add some spam comments related words. We will write about “Comments Moderation” in next coming days.

how to disable disqus for custom post types in wordpress

Earlier we also used disqus comment system. But now we stopped using disqus. Disqus comment system is most powerful and popular third-party comments tool. this tool is really great. With disqus you don’t need to worry about spam comments. Some times we faced slowness with disqus comments system so we stopped using disqus comments system.

If you want to use disqus comment system then go to following URL and download from here

Disqus Comment System

Disqus, pronounced “discuss”, is a service and tool for web comments and discussions. Disqus makes commenting easier and more interactive, while connecting websites and commenters across a thriving discussion community. The Disqus for WordPress plugin seamlessly integrates using the Disqus API and by syncing with WordPress comments.

how to disable disqus for custom post types in wordpress

If you are creating premium theme. Or you are trying to create the wordpress theme for your client than you need to control everything through your theme control panel. Using following code you can easily control disqus comment system through your wordpress theme code.

how to disable disqus for custom post types in wordpress
how to disable disqus for custom post types in wordpress

We given step for disable disqus for custom post types in wordPress with code.

What you need is, just copy and paste following code in functions.php file (wordpress theme).  Use following code.

add_filter( 'comments_template' , 'wpb_block_disqus', 1 );
function wpb_block_disqus($file) {
if ( 'custom_post_type_name' == get_post_type() )
remove_filter('comments_template', 'dsq_comments_template');
return $file;
}

Note: do not forget to change the “custom_post_type_name” name as per your custom post name.
Above code will check for custom post type and if current post with given custom post name than disqus comments will be disabled. This is safe way to disable disqus comments for custom posts.

You can use the Appearance ->Editor option also. Open functions.php file in Editor and at end of file Just put above code.

Following are some Useful article related to wordpress comments:

Select default image size for gallery in wordpress

In wordpress image gallery, it uses the full image size by default for every gallery but you can select or set the another image size. Using following code you can set the default image size for your wordpress image gallery.

Select default image size for gallery in wordpress

just copy and paste following code to your functions.php file:

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
 remove_shortcode('gallery');
 add_shortcode('gallery', 'custom_size_gallery');

 function custom_size_gallery($attr) {
      $attr['size'] = 'medium';
      return gallery_shortcode($attr);
 }
?>
default image size for gallery
default image size for gallery

Load jQuery in wordpress footer section will be best

Many latest framework are loading all javascript in footer. They reduce the page loading the errors. But wordpress load the jquery and other javascript in header.

loading javascript libraries in footer will be always best for every web or mobile application. Here in this article, I will show to Load jQuery in wordpress footer section.
But using following code you can load your javascripts and jquery in footer area. You just need to copy and paste the following code into the functions.php file.

Load jQuery in wordpress footer section

function wpai_add_jquery_in_footer( &$scripts) {
	if ( ! is_admin() )
		$scripts->add_data( 'jquery', 'group', 1 );
}
add_action( 'wp_default_scripts', 'wpai_add_jquery_in_footer' );

After doing the this you js scripts will load in footer. This js will load in footer for only normal users, Not for admin user.

Load jQuery in wordpress footer section will be best
Load jQuery in wordpress footer section will be best

 

Count post views without wordpress plugin

There are many wordpress plugin which will give you the post views using custom tables. But here using following code you can track the post views of your wp site.

Using external plugin, you can get the views and report but it will add more sql quries and extra load to your site. So I suggest use following code for getting the post views.

Count post views without wordpress plugin

Following code will track post views or count views of your wp site. You just need to copy and paste the following code into functions.php file first.


function getPostViews($postID){
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
        return "0 View";
    }
    return $count.' Views';
}
function setPostViews($postID) {
    $count_key = 'post_views_count';
    $count = get_post_meta($postID, $count_key, true);
    if($count==''){
        $count = 0;
        delete_post_meta($postID, $count_key);
        add_post_meta($postID, $count_key, '0');
    }else{
        $count++;
        update_post_meta($postID, $count_key, $count);
    }
}
// Remove issues with prefetching adding extra views
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);

After adding the above code for tracking the post views you need to add following code into single.php file. Note: add following code inside the wp post loop.

<?php
          setPostViews(get_the_ID());
?>

For showing the post views you need to put following code in single.php file. Note: add following code inside the wp post loop.

<?php
          echo getPostViews(get_the_ID());
?>
Count post views without wordpress plugin
Count post views without wordpress plugin

Ref taken from: http://wpsnipp.com/index.php/functions-php/track-post-views-without-a-plugin-using-post-meta/

Remove short words from wordpress permalink URL

WordPress itself creates the permalink. WordPress permalinks are very important for SEO purpose. Short words are sometimes are not good for seo so you might need to remove the short words from permalink. Using the following code you can remove the short words from wordpress permalink URL.

Using code you can Remove short words from wordpress permalink.

You just need to add the following code functions.php file.

add_filter('sanitize_title', 'remove_short_words');
function remove_short_words($slug) {
 if (!is_admin()) return $slug;
 $slug = explode('-', $slug);
 foreach ($slug as $k => $word) {
 if (strlen($word) < 3) {
 unset($slug[$k]);
 }
 }
 return implode('-', $slug);
}

 

Source Link :wpsnipp.com

 

social media bookmark in wordpress without javascript

All scripts and social media plugin add extra javascript code to site. I have best solution for adding social media bookmark in wordpress without javascript.

social media bookmark in wordpress without javascript

I used many types for social bookmark plugins for sharing the content. I tried a some best services like those provided by AddThis and ShareThis. All the scripts and social media bookmarks are adding the some extra javascript code to website. Some social media buttons will add the swf/ flash code to website which to too heavy. So Adding the multiple javascript files for each social media bookmark is not a good solution.

My suggestion is, use anchor links with parameters added to the href attribute (which is basically what you get anyway once those JavaScripts have done their work).

Following code are important in wordpress for sharing the content to social media sites:
<?php the_title(); ?> // It will return the Post/Article Title
<?php the_permalink(); ?> // It will return the Post/Article Permalink or URL
<?php the_excerpt(); ?> // It will return the Post/Article Description
<?php the_post_thumbnail(); ?> // It will return the Post/Article Thumbnail Image

For Facebook: social media bookmark in wordpress without javascript

Facebook Share

<a href="http://www.facebook.com/sharer.php?s=100&amp;p[title]=<?php the_title(); ?>&amp;p[summary]=<?php the_excerpt(); ?>&amp;p[url]=<?php the_permalink(); ?>&amp;&p[images][0]=<?php the_post_thumbnail(); ?>"><img src="http://images.purabtech.in/facebook_32.png" title="Facebook" alt="Facebook" /></a>

For Twitter: social media bookmark in wordpress without javascript

Twitter Share

<a href="https://twitter.com/share" class="twitter-share-button" data-text="some description goes here.some description goes here.some description goes here.some description goes here.some description goes here." data-url="https://purabtech.in/create-install-script-drupal-module-create-tables/" data-related="anywhere:The Javascript API" data-via="purab">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>

For Google plus: social media bookmark in wordpress without javascript

Google Plus

<a href="https://plus.google.com/share?url=http://54.214.47.229/test2.html?desc=foobar" onclick="javascript:window.open(this.href,
 '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;"><img
 src="https://www.gstatic.com/images/icons/gplus-64.png" alt="Share on Google+"/></a>

For Linked in: social media bookmark in wordpress without javascript

Linked In Share

<a rel="nofollow" target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=<?php the_permalink() ?>&amp;title=<?php echo urlencode(the_title('','', false)) ?>&amp;source=<?php bloginfo('pingback_url'); ?>&amp;ary=<?php the_excerpt(); ?>" title="LinkedIn">
<img src="http://images.purabtech.in/linkedin_32.png" title="LinkedIn" alt="LinkedIn" /></a>

For delicious: social media bookmark in wordpress without javascript

Delicious Bookmark

<a rel="nofollow" target="_blank" href="http://del.icio.us/post?url=<?php the_permalink() ?>&amp;title=<?php echo urlencode(the_title('','', false)) ?>" title="del.icio.us"><img src="http://images.purabtech.in/delicious_32.png" title="del.icio.us" alt="del.icio.us" /></a>

For Stumbleupon: social media bookmark in wordpress without javascript

Stumbleupon Share

<a rel="nofollow" target="_blank" href="http://www.stumbleupon.com/submit?url=<?php the_permalink() ?>&amp;title=<?php echo urlencode(the_title('','', false)) ?>" title="StumbleUpon"><img src="http://images.purabtech.in/stumbleupon_32.png" title="StumbleUpon" alt="StumbleUpon" /></a>

For Digg: social media bookmark in wordpress without javascript

Digg Share

<a rel="nofollow" target="_blank" href="http://digg.com/submit?phase=2&amp;url=<?php the_permalink() ?>&amp;title=<?php echo urlencode(the_title('','', false)) ?>" title="Digg"><img src="http://images.purabtech.in/digg_32.png" title="Digg" alt="Digg" /></a>

For Pinterest: social media bookmark in wordpress without javascript

Pin It

<a href="//www.pinterest.com/pin/create/button/?url=http%3A%2F%2Fwww.flickr.com%2Fphotos%2Fkentbrew%2F6851755809%2F&media=http%3A%2F%2Ffarm8.staticflickr.com%2F7027%2F6851755809_df5b2051c9_z.jpg&description=Next%20stop%3A%20Pinterest" data-pin-do="buttonPin" data-pin-config="above"><img src="//assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png" /></a>

For Mixx: social media bookmark in wordpress without javascript

Mixx Share

<a rel="nofollow" target="_blank" href="http://www.mixx.com/submit?page_url=<?php the_permalink() ?>&amp;title=<?php echo urlencode(the_title('','', false)) ?>" title="Mixx"><img src="http://images.purabtech.in/mixx_32.png" title="Mixx" alt="Mixx" />

For Reddit: social media bookmark in wordpress without javascript

Reddit Share

<a rel="nofollow" target="_blank" href="http://reddit.com/submit?url=<?php the_permalink() ?>&amp;title=<?php echo urlencode(the_title('','', false)) ?>" title="Reddit"><img src="http://images.purabtech.in/reddit_32.png" title="Reddit" alt="Reddit" /></a>

For Mail: social media bookmark in wordpress without javascript

Mail to

<a rel="nofollow" target="_blank" href="mailto:?subject=<?php echo urlencode(the_title('','', false)) ?>&amp;body=<?php the_permalink() ?>" title="E-mail this story to a friend!">
<img src="http://images.purabtech.in/email_32.png" title="E-mail this story to a friend!" alt="E-mail this story to a friend!" /></a>

For RSS feed: social media bookmark in wordpress without javascript

RSS feed

<a rel="nofollow" target="_blank" href="https://purabtech.in/feed" title="RSS">
<img src="http://images.purabtech.in/rss_32.png" title="RSS" alt="RSS" /></a>
social media bookmark in wordPress without javascript
social media bookmark in wordPress without javascript

I used following URL as reference.
How to Add the social Bookmark Icons in WordPress theme without wordpress plugins