WordPress: Remove Gravatar

A quick tip to remove default wordpress Gravatar avatar links. “avatar.jpg” is default avatar locates at theme directory/images folder, you can change it to any image you want.

// Remove Gravatar
function bp_remove_gravatar ($image, $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir) {
 
	$default = get_stylesheet_directory_uri() .'/images/avatar.jpg';
 
	if( $image && strpos( $image, "gravatar.com" ) ){ 
 
		return '<img src="' . $default . '" alt="avatar" class="avatar" ' . $html_width . $html_height . ' />';
	} else {
		return $image;
 
	}
 
}
add_filter('bp_core_fetch_avatar', 'bp_remove_gravatar', 1, 9 );
 
function remove_gravatar ($avatar, $id_or_email, $size, $default, $alt) {
 
	$default = get_stylesheet_directory_uri() .'/images/avatar.jpg';
	return "<img alt='{$alt}' src='{$default}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />";
}
 
add_filter('get_avatar', 'remove_gravatar', 1, 5);
 
function bp_remove_signup_gravatar ($image) {
 
	$default = get_stylesheet_directory_uri() .'/images/avatar.png';
 
	if( $image && strpos( $image, "gravatar.com" ) ){ 
 
		return '<img src="' . $default . '" alt="avatar" class="avatar" width="60" height="60" />';
	} else {
		return $image;
	}
 
}
add_filter('bp_get_signup_avatar', 'bp_remove_signup_gravatar', 1, 1 );

CSS3: Change DIV CSS onhover (:active, :focus, :disabled, :checked)

You can do this by jquery but there is an easier way to change Div CSS by using CSS3: transition

Support: Firefox (-moz-), Chrome (-webkit-), Opera (-o-), Safari (-webkit-), IE10 (-ms-)

My example is about changing max-height of a DIV from 200px to 400px on hover, also after 5 seconds the DIV max-height will roll back to previous position:

#my-example {
     max-height: 200px;
     overflow:hidden;
    -webkit-transition: .5s all;   
    -webkit-transition-delay: 5s;
    -moz-transition: .5s all;   
    -moz-transition-delay: 5s;
    -ms-transition: .5s all;   
    -ms-transition-delay: 5s;
    -o-transition: .5s all;   
    -o-transition-delay: 5s;
    transition: .5s all;   
    transition-delay: 5s;  
}
 
#my-example:hover {
    max-height:400px;
    -webkit-transition-delay: 0s;
    -moz-transition-delay: 0s;
    -ms-transition-delay: 0s;
    -o-transition-delay: 0s;
    -transition-delay: 0s;
}

Demo: http://jsfiddle.net/j3Azt/

You can do the same with :active, :focus, :disabled, :checked event.

Thanks.

Quick tips: Compress/Extract Linux directory with Tar command

To compress:

tar -zcvf archive-name.tar.gz directory-name
    -z: Compress archive using gzip program
    -c: Create archive
    -v: Verbose i.e display progress while creating archive
    -f: Archive File name

To Extract:

tar -zxvf archive-name.tar.gz /to/bath/directory-name
    -z: Compress archive using gzip program
    -x: Extract files
    -v: Verbose i.e display progress while creating archive
    -f: Archive File name

WordPress: Add custom post-types to main query

Some days ago, i had a problem with my website and wordpress post-types. I added some custom post-types but couldnt show those posts on my homepage because by default, main post query just fetchs posts from post-type POST, not from all custom post-types. Finally, i fixed that issue with below extra code. The code should be added to function.php of your theme.

// Add custom post types to main query
add_filter( 'pre_get_posts', 'my_get_post_types' );
 
function my_get_post_types( $query ) {
 
	if ( is_home() && $query->is_main_query() )
		$query->set( 'post_type', array( 'post', 'videos', 'cheats', 'photos') ); // add your custom post-type here
 
	return $query;
}

Cheers.

Add wordpress custom post-type & comments to Buddypress activity record

By default, Buddypress will not record custom post-type posts and comments. To do that, you can add following functions to your theme function.php file.

// Add custom post type to activity record
add_filter ( 'bp_blogs_record_post_post_types', 'activity_publish_custom_post_types',1,1 );
// Add custom post type comments to activity record
add_filter ( 'bp_blogs_record_comment_post_types', 'activity_publish_custom_post_types',1,1 );
 
function activity_publish_custom_post_types( $post_types ) {
// add any custom post-type here
$post_types[] = 'videos';
$post_types[] = 'photos';
$post_types[] = 'cheats';
return $post_types;
}
 
//Modify activity records for custom post-type
add_filter('bp_blogs_activity_new_post_action', 'record_cpt_activity_action', 1, 3);
function record_cpt_activity_action( $activity_action,  $post, $post_permalink ) {
global $bp;
if( $post->post_type != 'post' ) {
	if ( is_multisite() )
	$activity_action  = sprintf( __( '%1$s wrote a new %2$s post, %3$s, on the site %4$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), $post->post_type, '<a href="' . $post_permalink . '">' . $post->post_title . '</a>', get_blog_option( $blog_id, 'blogname' ));
	else
	$activity_action  = sprintf( __( '%1$s wrote a new %2$s post, %3$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ),$post->post_type, '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
} 
return $activity_action;
}
 
//Modify activity comment records for custom post-type
add_filter('bp_blogs_activity_new_comment_action', 'record_cpt_comment_activity_action', 1, 3);
function record_cpt_comment_activity_action( $activity_action,  &$recorded_comment, $comment_link ) {
global $bp;
if( $recorded_comment->post->post_type != 'post' ) {
		if ( is_multisite() )
			$activity_action = sprintf( __( '%1$s commented on the %2$s post, %3$s, on the site %4$s', 'buddypress' ), bp_core_get_userlink( $user_id ), $recorded_comment->post->post_type, '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' );
		else
			$activity_action = sprintf( __( '%1$s commented on the %2$s post, %3$s', 'buddypress' ), bp_core_get_userlink( $user_id ),$recorded_comment->post->post_type, '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' );
} 
return $activity_action;
}

Hope this is useful for your project!

WordPress: Required Password at Register Form

By default, WordPress dont have function to allow users choose their own password when registering on your blog. For security purpose, Password will be mailed to your registration email, but sometime users dont change their password at the first time they log in to your blog; the result is they will forget it or hard to find the password in mailbox. If you want to let them choose their password, you have to write some code to add Password fields to your blog register form. Here its:
Continue reading WordPress: Required Password at Register Form

Nameserver IPs not showing in WHM?

Hi everyone, I have faced with a Nameserver Ips issue, thats my “Nameserver IPs” section won’t show ips in WHM. All ips are present in /etc/nameserverips file but still ips missing.

So How to fix that? i found a solution and want to share again with you, hope this tip will be helpful. Please follow the steps:

– Firstly, check the entries in /etc/nameserverips file, it should look like the below command output

root@root[~]# cat /etc/nameserverips
198.168.0.1=ns1.test.com
198.168.0.2=ns2.test.com

In that case correct ips entry in the following /var/cpanel/nameserverips.yaml file.

/var/cpanel/nameserverips.yaml entries should be like this:

root@root [~]# cat /var/cpanel/nameserverips.yaml
—
ns1.test.com:
“198.168.0.1″: 1
count: 1
zones: test.com
ns2,.test.com:
198.168.0.2: 1
count: 1
zones: test.com

If your files are not showing properly, so you should edit those files following the examples above.

nano /etc/nameserverips
nano /var/cpanel/nameserverips.yaml

Now, go to your WHM and check Nameserver Ips section, your ips should be there :)

Thank you

5 Common SEO mistakes & 6 SEO Tips

5 common mistakes

1. Having no value proposition: Try not to assume that a site should rank #1 without knowing why it’s helpful to searchers (and better than the competition :)

2. Segmented approach: Be wary of setting SEO-related goals without making sure they’re aligned with your company’s overall objectives and the goals of other departments. For example, in tandem with your work optimizing product pages (and the full user experience once they come to your site), also contribute your expertise to your Marketing team’s upcoming campaign. So if Marketing is launching new videos or a more interactive site, be sure that searchers can find their content, too.

3. Time-consuming workarounds: Avoid implementing a hack rather than researching new features or best practices that could simplify development (e.g., changing the timestamp on an updated URL so it’s crawled more quickly instead of easily submitting the URL through Fetch as Googlebot).

4. Caught in SEO trends: Consider spending less time obsessing about the latest “trick” to boost your rankings and instead focus on the fundamental tasks/efforts that will bring lasting visitors.

5. Slow iteration: Aim to be agile rather than promote an environment where the infrastructure and/or processes make improving your site, or even testing possible improvements, difficult.
Continue reading 5 Common SEO mistakes & 6 SEO Tips

Buddypress: Disable Register page redirection

After installing Buddypress, you may notice that default register url is redirected to “Register Page” of Buddypress.
http://www.example.com/wp-login.php?action=register
to
http://www.example.com/register

What if you want to keep default register url of wordpress and “Register page” of buddypress still works. A simply way to do that, we can disable Buddypress redirection function by putting the code below into your theme function.php file.

/** Disable BuddyPress Register page redirection http://www.adminblog.com **/
if ( bp_core_is_multisite() )
	remove_action( 'wp', 'bp_core_wpsignup_redirect' );
else
	remove_action( 'bp_init', 'bp_core_wpsignup_redirect' );

Thank you.

PHP: How to get meta tags from a webpage

A simple php function which help you fetch meta tags from a webpage. We will use get_meta_tags function:

$tags = get_meta_tags('http://www.example.com/');
 
echo $tags['author'];       // Meta author name
echo $tags['keywords'];     // Meta keywords
echo $tags['description'];  // Meta Description
echo $tags['geo_position']; // Meta geo Position

And to avoid 404 header response code, you can add an additional function to check header code:
Continue reading PHP: How to get meta tags from a webpage