Tuesday, March 12, 2013

Image resizing using jQuery

Image resizing using jQuery

Example of  jquery fixed image resize


$(window).bind("load", function() {
 // IMAGE RESIZE
 $('#product_cat_list img').each(function() {
  var maxWidth = 120;
  var maxHeight = 120;
  var ratio = 0;
  var width = $(this).width();
  var height = $(this).height();
 
  if(width > maxWidth){
   ratio = maxWidth / width;
   $(this).css("width", maxWidth);
   $(this).css("height", height * ratio);
   height = height * ratio;
  }
  var width = $(this).width();
  var height = $(this).height();
  if(height > maxHeight){
   ratio = maxHeight / height;
   $(this).css("height", maxHeight);
   $(this).css("width", width * ratio);
   width = width * ratio;
  }
 });
 //$("#contentpage img").show();
 // IMAGE RESIZE
});
 
 
Source: http://snipplr.com/view/62552/mage-resize/ 


Monday, March 11, 2013

How to make WordPress images responsive

How to make WordPress images responsive

The responsive images can be big on wide screens but automatically adapt to smaller screens such as iphone,iPad. Very easily you can make images responsive. Just follow the simple steps on your blog.


First you have to create the shortcode. Open your functions.php file and paste the following php code in it:

function responsive_images($atts, $content = null) {
     return '<div class="image-resized">' . $content .'</div>';
}

add_shortcode('responsive', 'responsive_images');

Now after that open your style.css file and add those CSS rules:

@media only screen and (max-width:767px) {
    .image-resized img {
        width:100%;
        height:auto;
    }
}

So now you can use the [responsive] shortcode to insert responsive images in your wordpress blog:

[responsive]<img src="image_url" alt="alt" title="title" />[/responsive]

Sql query to delete orphaned post meta from WordPress database

Sql query to delete orphaned post meta from WordPress database

WordPress blog contain thousands of rows of useless meta data. The following simple SQL query can delete orphaned post meta on our database.


You have to just run the following sql query on the WordPress database which delete orphaned post meta.
Before you start, create a backup of your database!

DELETE pm
FROM wp_postmeta pm
LEFT JOIN wp_posts wp ON wp.ID = pm.post_id
WHERE wp.ID IS NULL

Sunday, February 24, 2013

Disable automatic paragraphs in WordPress editor

How to disable automatic paragraphs in WordPress editor

WordPress by default automatically creates paragraphs on the post content. Sometimes this is very useful, but sometimes we might want to change this type of behavior which can fit our specific needs. The following recipe explains how we can disable automatic paragraphs in wordpress.



JUst paste the following line into the theme functions.php file:

remove_filter('the_content', 'wpautop');

Now  Once you saved the file then the WordPress will never create automatic paragraphs on the wordpress post or page content.

Tuesday, January 22, 2013

Shortcode to display external files on Wordpress post

Shortcode to display external files on Wordpress post

While blogging on wordpress, sometimes we may need to include an external file on our post, like text or image etc, into our wordpress posts. Checkout the following a very useful shortcode which embed and display any external files in our wordpress blog posts.


function show_file_func( $atts ) {
  extract( shortcode_atts( array(
    'file' => ''
  ), $atts ) );
 
  if ($file!='')
    return @file_get_contents($file);
}
 
add_shortcode( 'show_file', 'show_file_func' );
 
 
Now use the shortcode like the following example

[show_file file="http://www.thesandip.com/test.html"] 

Monday, December 10, 2012

Important Methods for On Page Optimization

The following process need to do for on page optimization in SEO.

    Keyword Research and Analysis
    Keyword Density
    Title Tag (Page Title Optimization)
    Page Specific Meta Tag Creation
    Anchor Text Optimization
    Alt Tag Optimization
    Submission of XML Sitemap
    Content Placement  
    Implementation of Google Analytic
    Search Engine Verification from Google, Yahoo and MSN
    Creation and Submission of ROR.xml
    Creation of Proper Link Structure
    Implementation of 301 Permanent Redirect
    Optimization of Search Engine Essential Files (robots.txt, urllist.txt, sitemap.xml)
    Creating micro-formats like hcard integration, hrview integration, vCard integration.

Thursday, December 6, 2012

How to get the first link in wordpress posts

How to get the first link in wordpress posts

Please follow the code structure to get the first link from a post.


To make this happen just paste this code into your functions.php file.

function get_content_link( $content = false, $echo = false ){
    if ( $content === false )
        $content = get_the_content();

    $content = preg_match_all( '/hrefs*=s*["']([^"']+)/', $content, $links );
    $content = $links[1][0];

    if ( empty($content) ) {
        $content = false;
    }

    return $content;
}

The above function finds the first link in the post and returns that link to you. So In this following way, we can link the title(or whatever) to this place, as describe below:

<h2><a href="<?php echo get_content_link( get_the_content() ); ?>"><?php the_title(); ?></a></h2>

Tuesday, November 27, 2012

How to create a Pinterest "pin it" button for your WordPress blog

How to create a Pinterest "pin it" button for your WordPress blog

Just paste the following code where you like the "Pin It" button to be displayed. But remeber that this code must be inserted within the loop.

<a href="http://pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail' ); echo $thumb['0']; ?>&description=<?php the_title(); ?>" class="pin-it-button" count-layout="horizontal">Pin It</a>

Now footer.php file and add the pinterest JavaScript code:

<script type="text/javascript" src="http://assets.pinterest.com/js/pinit.js"></script>

Thursday, November 22, 2012

Automatic “Nofollow” for external links in post content of wordpress

Automatic “Nofollow” for external links in post content of wordpress

WordPress hack: Automatic “Nofollow” for external links in post content of wordpress

WordPress does not automatically by default add a rel=”nofollow” attribute to its external links within the post content. But If you want to add this attribute, the following solution help you to force WordPress to add the rel=”nofollow” attribute to every external link.

To make this work just Paste the following code in the functions.php file. Now save the file, you can see that all external links in your post content will be changed to nofollow.

add_filter('the_content', 'auto_nofollow');

function auto_nofollow($content) {
    //return stripslashes(wp_rel_nofollow($content));

    return preg_replace_callback('/<a>]+/', 'auto_nofollow_callback', $content);
}

function auto_nofollow_callback($matches) {
    $link = $matches[0];
    $site_link = get_bloginfo('url');

    if (strpos($link, 'rel') === false) {
        $link = preg_replace("%(href=S(?!$site_link))%i", 'rel="nofollow" $1', $link);
    } elseif (preg_match("%href=S(?!$site_link)%i", $link)) {
        $link = preg_replace('/rel=S(?!nofollow)S*/i', 'rel="nofollow"', $link);
    }
    return $link;
}

How to remove WordPress version number from pages and feeds

How to remove WordPress version number from pages and feeds

WordPress always publicly display wordpress version number in RSS and Atom feeds by default. With the following solution we can remove those wordpress version number from all our blog feeds.

You need to just use this code in functions.php file

add_filter('the_generator', 'digwp_complete_version_removal');
function digwp_complete_version_removal() {
    return '';
}

I just got my #domain @BigRock. Get upto 25% off with my personalized coupon link Get upto 25% off