Categories
Wordpress

Disable Update Notification for Individual WordPress Plugins

Well i strongly recommend to update the WordPress plugin whenever a new update is available. This is required for proper functioning of your WordPress website and also prevents hacking of your WordPress website. Plugin developers are constantly fixing bugs, closing security gaps, increasing efficiency, and updating other aspects of the plugin that will benefit your site.

But there might be a situation where you would want to hide a plugin update notification. Suppose if are working for some non technical client or if you have made some modifications to a plugin that you don’t want to be overwritten?

Here are 2 simple tricks to hide the plugin update notification.

Trick 1 – Modify Plugin Version
The easiest solution is to open up the PHP file in the plugin root directory and modify the version number. At the top of the file, there will be some commented out variables that WordPress pulls in. You can update the plugin version from 1.1 to 100.1. A version number so high that the plugin will never get there, for example 100.1.

Plugin Name: WordPress PopUp
Plugin URI: http://premium.wpmudev.org/project/the-pop-over-plugin/
Description: Please don’t upgrade this plugin. If required then please contact Vaseem Ansari to upgrade it. Allows you to display a fancy PopUp to visitors site wide or per blog. A *very* effective way of advertising a mailing list, special offer or running a plain old ad.
Version: 1.1.2
Author: WPMU DEV
Author URI: http://premium.wpmudev.org
Textdomain: popover
WDP ID: 123

Trick 2 – Prevent Update Notification by Modifying Theme functions.php file
Another solution is to open the functions.php file of your WordPress theme and add the below function there. This function will disable the individual plugin update notifications in WordPress admin. By using this trick you can disable update notifications for specific/individual plugin.

/**
* Hide the notice of plugin update available in admin There is a new version of WordPress PopUp available. View version 1.1.3 details or update now.
* Usage – Automatic
*/
function hide_akismet_plugin_updates( $value ) {
unset( $value->response[‘akismet/akismet.php’] ); // For example if you don’t want WordPress to show update notifications for akismet plugin.
return $value;
}
add_filter( ‘site_transient_update_plugins’, ‘hide_akismet_plugin_updates’ );

function hide_wordpress_popup_plugin_updates( $value ) {
unset( $value->response[‘wordpress-popup/popover.php’] ); // For example if you don’t want WordPress to show update notifications for wordpress-popup plugin.
return $value;
}
add_filter( ‘site_transient_update_plugins’, ‘hide_wordpress_popup_plugin_updates’ );

Some Useful Reference
Disable update notification for individual plugins
Disable All WordPress Updates
7 Ways to Disable Update Notifications and Maintenance Nags in WordPress

Categories
jQuery PHP Wordpress

WordPress : How to Add Infinite Scroll to Home & Category Pages

I was working on Infinite Scroll functionality in WordPress. Initially i was trying to use jetpack (WordPress plugin) to implement the same but i was not able to understand how jetpack works and i did not get proper screenshot and online support to make me understand it properly. So i have Goggled more and finally i successfully implemented Infinite Scroll on VaseemAnsari.com. You can check the home page, category page, archive page and other pages where pagination generally comes.

Let me guide you how easy it is and how can you implement the same Infinite Scroll on your WordPress blog.
Step 1. This simple functionality uses javascript “jquery.infinitescroll.min.js”. You can download a copy of “jquery.infinitescroll.min.js” from the GitHub repository, and drop it into the “scripts” or “js” folder of your WordPress theme.

Step 2. Use any Ajax loader image. I hope you already have so many or you can find loading images on Google. You can pick out the ajax-loader.gif of your choice, and add it to your theme “images” folder.

Step 3. You need to register and enqueue the required jquery.infinitescroll.min.js script in functions.php (You can find this file in your wordpress theme.)

function custom_theme_js(){
	wp_register_script( 'infinite_scroll',  get_template_directory_uri() . '/js/jquery.infinitescroll.min.js', array('jquery'),null,true );
	if( ! is_singular() ) {
		wp_enqueue_script('infinite_scroll');
	}
}
add_action('wp_enqueue_scripts', 'custom_theme_js');

Step 4. Then you need yo use below function to make the magic happen. You can write this function in functions.php file.

function custom_infinite_scroll_js() {
	if( ! is_singular() ) { ?>
	<script>
	var infinite_scroll = {
		loading: {
			img: "<?php echo get_template_directory_uri(); ?>/images/ajax-loader.gif",
			msgText: "<?php _e( 'Loading the next set of posts...', 'custom' ); ?>",
			finishedMsg: "<?php _e( 'All posts loaded.', 'custom' ); ?>"
		},
		<?php /*?>
			img				: 	The path to the ajax loader image, we put the image in plugin folder
			nextSelector	: 	Selector for the “previous posts” link.
			navSelector		: 	Containing selector for the previous/next navigation links.
			itemSelector	: 	Selector for posts. This might be .hentry, .post, .etc
			contentSelector	: 	Containing div for your posts
		<?php */?>
		"nextSelector":"#nav-below .nav-previous a",
		"navSelector":"#nav-below",
		"itemSelector":"article",
		"contentSelector":"#content"
	};
	jQuery( infinite_scroll.contentSelector ).infinitescroll( infinite_scroll );
	</script>
	<?php
	}
}
add_action( 'wp_footer', 'custom_infinite_scroll_js',100 );

Check out below screenshot to know how Infinite Scroll works on my blog Twenty Thirteen and Twenty Twelve theme.

Simple Steps to add Infinite Scroll to a WordPress Blog
I have added Infinite Scroll functionality on my WordPress website. Check out the home page to see how it works

I have added Infinite Scroll to WordPress Twenty Thirteen and Twenty Twelve theme. If you have any issue in finding the proper div selectors of your theme then check below images. These images will help you to find selectors in Twenty Thirteen and Twenty Twelve Theme

You can see the Infinite Scroll working at below urls.
Twenty Thirteen Theme
Twenty Twelve Theme

I hope the above work out for you and if you still feel any issues then check the original link that helped me a lot.
Source

Categories
PHP Wordpress

WordPress : Redirect To Post Page When Search Query Returns Single Result

If your website have lots of links and people often use search box to search what they are looking for. When there is only one search result then user need to click on the title of that result to read more about that post. A solution here is why we need to show the search results page when there are only one search result.

You may use below simple php code in your WordPress theme’s functions.php file to redirect your search to the post automatically when WordPress only returns a single search result.


if (!function_exists('single_result_redirect_to_post')){
	add_action('template_redirect', 'single_result_redirect_to_post');
	function single_result_redirect_to_post(){
		if (is_search()) {
			global $wp_query;
			if ($wp_query->post_count == 1) {
				wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
			}
		}
	}
}
Categories
PHP Wordpress

WordPress : Send Mail to Admin when user comes to 404 page

Sending mails to admin is very easy in wordpress by using a inbuild wordpress function wp_mail.
But if you want to send a mail to wordpress admin when user comes to 404 page then you can use below simple code.

Sending mail when user comes to 404 page in wordpress
This code can be added in your wordpress theme’s functions.php file or in custom plugin. You need to write a custom plugin for the same. Please let me know if you need any help to write a custom plugin. As i am using a custom plugin for my wordpress websites and that custom plugin have lots of functions and wordpress hooks that makes my life easy and simple.

Below script checks the referring link of your website, and then sends an email to the webmaster/wordpress admin.

if (!function_exists('email_admin')){
	function email_admin(){
		$message = "";
		if(isset($_SERVER['HTTP_REFERER'])){
			$message .= "User came from: ".$_SERVER['HTTP_REFERER']."\r\n";
		}
		$ipAddress 		= 	$_SERVER["REMOTE_ADDR"];
		if($ipAddress!=''){
			$message .= "Track User Data: http://www.ip-adress.com/ip_tracer/".$ipAddress."\r\n";
		}
		$browser 		= 	$_SERVER['HTTP_USER_AGENT'];
		if($browser!=''){
			$message .= "Browser: ".$browser."\r\n";
		}
		$message.="Page URL they tried to access was: ".home_url().$_SERVER['REQUEST_URI']."\r\n";
		$admin_email 	= 	get_option('admin_email');
		$subject		=	'404 Error at '. home_url();
		//echo $subject;	echo $message; die;
		@wp_mail($admin_email,$subject,$message);
	}
	
	function mail_me_errors(){
		global $wp_query;
		if ($wp_query->is_404){
			email_admin();
		}
	}
	add_action('get_header', 'mail_me_errors');
}