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.
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
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.
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.
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.
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.
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.
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.
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.
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, 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.
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:
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:
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.
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.
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());
?>
Ref taken from: http://wpsnipp.com/index.php/functions-php/track-post-views-without-a-plugin-using-post-meta/
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);
}
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
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)) ?>&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