Wednesday, November 30, 2011

Automatically remove p tags on images in wordpress

Automatically remove p tags on images in wordpress
Wordpress By default embed images in < p > tags. but if you don’t want those p tags to show, the following example display a great way to remove the < p > tags without having to chnage the WordPress core

Just paste the following code in theme functions.php file, and save the file.the
tags are gone now.





add_filter('the_content', 'remove_ptags_on_images');

Monday, October 31, 2011

Login form shortcode for WordPress

Here we learn how to displaying login forms on wordpress using a shortcode Paste the following code into functions.php file:

function sandip_login_form_shortcode() {
    if ( is_user_logged_in() )
        return '';

    return wp_login_form( array( 'echo' => false ) );
}

function sandip_add_shortcodes() {
    add_shortcode( 'sandip-login-form', 'sandip_login_form_shortcode' );
}

add_action( 'init', 'sandip_add_shortcodes' );

Once done, we can now use the shortcode as shown in the following example. just paste it on the post editor, where you want the login form to be displayed. [sandip-login-form]

Friday, September 30, 2011

Retrieve a remote page using WordPress

How to retrieve a remote page using WordPress


If you want to get the content,file info from a remote file for use it in wordpress instal then follow the step describe below.
Use the wp_remote_get() function (Or wp_remote_post() is you prefer using the POST method) to retrieve the desired url. The following example describe how to retrieve an url and display its content as well as the file info.

This code can be used anywhere on your template files.

$response = wp_remote_get( 'http://sandipdas.in/file.txt' );
if( is_wp_error( $response ) ) {
echo 'Something went wrong!';
} else {
echo 'Response:';
print_r( $response );

';
}

Wednesday, September 28, 2011

Display your latest Google+ update on WordPress

How to display your latest Google+ update on your WordPress blog


Just paste the following code where you want to display your latest Google+ update. Don't forget to put your Google+ ID on line 3.


include_once(ABSPATH.WPINC.'/rss.php');
$googleplus = fetch_feed("http://plusfeed.appspot.com/117307278436515842100

"); // Replace 117307278436515842100 by your own ID
echo '< a href="'; echo $googleplus->items[0]['link']; echo '">';
echo $googleplus->items[0]['summary'];


echo '';

Wednesday, August 24, 2011

Display a thumbnail of any website in wordpress

In WordPress we can display a thumbnail of any website. Wordpress have a service named mShots, Its allow us to get snapshots of any website. We can use a shotcode to easily display a snapshot of a given website.


To create the shortcode ,just paste the following code into functions.php file.



function wpr_snap($atts, $content = null) {
extract(shortcode_atts(array(
"snap" => 'http://s.wordpress.com/mshots/v1/',
"url" => 'http://www.sandipdas.in',
"alt" => 'My image',
"w" => '500', // width
"h" => '400' // height
), $atts));

$img = '' . $alt . '';
return $img;
}

add_shortcode("snap", "wpr_snap");


Now use the following shortcode to display any snaphot

[snap url="http://www.sandipdas.in" alt="description" w="500" h="400"]

Saturday, July 23, 2011

Display Custom Fields Outside Loop in WordPress

How to Display Custom Fields Outside The Loop in WordPress

When you need to display post-specific content for example a data for a specific post. Usually post specific contents are added via a custom field which can only be displayed inside a post loop.Here we will show you how you can display custom fields outside the loop.

Please check the following code:


global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'Your-Custom-Field-data', true);
wp_reset_query();


You will need to make sure that you change the part where it says “Your-Custom-Field-data”.

Tuesday, July 5, 2011

Wordpress Tricks

Get Category Name By ID (WordPress)
eho get_cat_name( $cat_id );


Get Category Link By ID (WordPress)
echo get_category_link($cat_id);

Sunday, June 26, 2011

A Custom Read More in Wordpress

Display A Custom Read More in Wordpress

To display "A Custom Read More" all you need to do is replace your usual the_content template tag with the following code. So when you write a new post, create a new custom field with the key name "custom_more".

$custommore = get_post_meta($post->ID, 'custom_more', true);
if (!$custommore) { $custommore = 'Read More »'; }
the_content($custommore);

Wednesday, June 15, 2011

Detect visitor browser within WordPress

How to detect the visitor browser within WordPress

To ensure maximum cross-browser compatibility on the wordpress blog theme, We have to able to detect the browser used by the blog visitor. WordPress can detect client browser. I describe the proces below.

Paste the code below in your functions.php file:


add_filter('body_class','browser_body_class');
function browser_body_class($classes) {
global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;

if($is_lynx) $classes[] = 'lynx';
elseif($is_gecko) $classes[] = 'gecko';
elseif($is_opera) $classes[] = 'opera';
elseif($is_NS4) $classes[] = 'ns4';
elseif($is_safari) $classes[] = 'safari';
elseif($is_chrome) $classes[] = 'chrome';
elseif($is_IE) $classes[] = 'ie';
else $classes[] = 'unknown';

if($is_iphone) $classes[] = 'iphone';
return $classes;
}


Now saved the file and the function will automatically add a CSS class to the body tag, as shown in the exemple below:

body class="home blog logged-in safari"

So now with the help of the code, you just have to take your stylesheet, and add some browser-specific styles!

Tuesday, May 24, 2011

Display Twitter-like “time ago” on WP

Display Twitter-like “time ago” on your WordPress blog

Twitter have a built-in function that display time from now, like “3 days ago” or “more than a month ago”.If you want to do same with your WordPress post use the following function.

Paste the following into your functions.php file:






function post_time_ago( $type = 'post' ) {
    $d = 'comment' == $type ? 'get_comment_time' : 'get_post_time';
    return human_time_diff($d('U'), current_time('timestamp')) . " " . __('ago');
}

Now, you can use the following function in your theme files:
 echo post_time_ago();

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