Saturday, June 16, 2012

How to Remove the Width and Height Attributes From WP Image Uploader

How to Remove the Width and Height Attributes From WP Image Uploader


When we upload images in WordPress using image uploader and insert that image into wordpress posts, WordPress always automatically include the image width and height attributes in the html <img> tag. But sometimes that can give us some problem, because that may not fit in our layout . So using the following code we can get rid of those height and width attributes.

Just paste the following code into  functions.php file under theme folder.

add_filter( 'post_thumbnail_html', 'remove_width_attribute', 10 );
add_filter( 'image_send_to_editor', 'remove_width_attribute', 10 );

function remove_width_attribute( $html ) {
   $html = preg_replace( '/(width|height)="\d*"\s/', "", $html );
   return $html;
}

Tuesday, June 5, 2012

How to display RSS feeds on WordPress

How to display RSS feeds on WordPress

If you ever want to display any rss feed on your WordPress blog then follow the process. The simple code that will do the job without using the deprecated wp_rss() function in wordpress.


The following code you have to paste in template pages wherever you wanna display the rss feed.
Please  update the feed url on line 3. and the Number of items you want to display can be defined on line 6.

<?php
include_once(ABSPATH . WPINC . '/rss.php');
$feed = 'http://sandipdas.in/feed';
$rss = fetch_feed($feed);
if (!is_wp_error( $rss ) ) :
    $maxitems = $rss->get_item_quantity(3);
    $rss_items = $rss->get_items(0, $maxitems);
    if ($rss_items):
        echo "<ul>\n";
        foreach ( $rss_items as $item ) :
            echo '<li>';
            echo '<a href="' . $item->get_permalink() . '">' . $item->get_title() . "</a>\n";
            echo '<p>' . $item->get_description() . "</li>\n";
        endforeach;
        echo "</ul>\n";
    endif;
endif;
?>

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