<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>beer planet &#187; remove</title>
	<atom:link href="http://beerpla.net/tag/remove/feed/" rel="self" type="application/rss+xml" />
	<link>http://beerpla.net</link>
	<description>where things have nothing to do with beer - tutorials, tips, how-tos, thoughts, hacks, and other techy nonsense</description>
	<lastBuildDate>Sun, 08 Aug 2010 23:59:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<atom:link rel='hub' href='http://beerpla.net/?pushpress=hub'/>
		<item>
		<title>How To Remove Inline Hardcoded Recent Comments Sidebar Widget Style From Your WordPress Theme</title>
		<link>http://beerpla.net/2010/01/31/how-to-remove-inline-hardcoded-recent-comments-sidebar-widget-style-from-your-wordpress-theme/</link>
		<comments>http://beerpla.net/2010/01/31/how-to-remove-inline-hardcoded-recent-comments-sidebar-widget-style-from-your-wordpress-theme/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 09:45:15 +0000</pubDate>
		<dc:creator>Artem Russakovskii</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[add_action]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[functions.php]]></category>
		<category><![CDATA[hardcoded]]></category>
		<category><![CDATA[inline]]></category>
		<category><![CDATA[recent]]></category>
		<category><![CDATA[recent_comments_style]]></category>
		<category><![CDATA[remove]]></category>
		<category><![CDATA[remove_action]]></category>
		<category><![CDATA[sidebar]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[widget]]></category>
		<guid isPermaLink="false">http://beerpla.net/2010/01/31/how-to-remove-inline-hardcoded-recent-comments-sidebar-widget-style-from-your-wordpress-theme/</guid>
		<description><![CDATA[<h2>The Problem</h2>
<p>If you use the Recent Comments sidebar widget in your WordPress installation, it&#039;s possible that you want to customize this widget&#039;s style.</p>
<p>You will quickly find, however, that as soon as you add the widget to your sidebar, it injects the following inline, hardcoded CSS into the containing page (using !important to make things worse):&#160; </p>
<div class="wp_syntax"><div class="code"><pre>&#60;style type=&#34;text/css&#34;&#62;.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}&#60;/style&#62;</pre></div></div>
<p>The code above comes from <strong><em>recent_comments_style()</em></strong> (found in wp-includes/default-widgets.php), which is in turn called by <strong><em>WP_Widget_Recent_Comments()</em></strong> in the same file (this is just an old-style PHP4 constructor &#8211; same as PHP5&#039;s __construct()), which is triggered...<div class=clear></div> <a href="http://beerpla.net/2010/01/31/how-to-remove-inline-hardcoded-recent-comments-sidebar-widget-style-from-your-wordpress-theme/" class="read_more"><div class=excerpt-end>Read the rest of this article &#187;</div></a></p>]]></description>
			<content:encoded><![CDATA[<h2>The Problem</h2>
<p>If you use the Recent Comments sidebar widget in your WordPress installation, it&#039;s possible that you want to customize this widget&#039;s style.</p>
<p>You will quickly find, however, that as soon as you add the widget to your sidebar, it injects the following inline, hardcoded CSS into the containing page (using !important to make things worse):&#160; </p>
<div class="wp_syntax"><div class="code"><pre>&lt;style type=&quot;text/css&quot;&gt;.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}&lt;/style&gt;</pre></div></div>
<p>The code above comes from <strong><em>recent_comments_style()</em></strong> (found in wp-includes/default-widgets.php), which is in turn called by <strong><em>WP_Widget_Recent_Comments()</em></strong> in the same file (this is just an old-style PHP4 constructor &#8211; same as PHP5&#039;s __construct()), which is triggered when the Recent Comments widget is used:</p>
<div class="wp_syntax"><div class="code"><pre>add_action( 'wp_head', array(&amp;$this, 'recent_comments_style') );</pre></div></div>
<p>This leaves a bad taste in my mouth because:</p>
<ul>
<li>the style is automatically forced into any page that embeds the widget </li>
<li>it uses !important to override any existing styles </li>
<li>it cannot be configured from the widget </li>
<li>this is a core WordPress widget and not some widget added by a random plugin. WordPress should not contain such bad practices. </li>
</ul>
<p>After seeing this, I raised a new <a href="http://core.trac.wordpress.org/ticket/11928" rel="nofollow">issue #11928</a> in the WordPress bug tracker but in the meantime, of course, I could go and hack the default-widgets.php core file to solve this problem. That, of course, would be a horrible thing to do &#8211; the next upgrade could wipe my changes or result in a conflict (if upgrading via svn). In general, one should never need to modify core files.</p>
<h2>The Solution</h2>
<p>Fortunately, there is a solution that doesn&#039;t involve modifying core files. Remember that we are talking about WordPress here, which gained its popularity due to the ease of customization.</p>
<p>Normally, we would just need to remove the <strong><em>recent_comments_style</em></strong> hook, which would prevent it from ever firing and injecting the CSS. In fact, <a href="http://webstractions.com/wordpress/remove-recent-comments-inline-styl/" rel="nofollow">somebody over at webstractions.com</a> already took a crack at this approach with the following code, which may have worked for a while but doesn&#039;t anymore:</p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre>function remove_wp_widget_recent_comments_style() {
   if ( has_filter('wp_head', 'wp_widget_recent_comments_style') ) {
      remove_filter('wp_head', 'wp_widget_recent_comments_style' );
   }
}
add_filter( 'wp_head', 'remove_wp_widget_recent_comments_style', 1 );</pre></td></tr></table></div>
<p>This code doesn&#039;t work in the current version of WordPress because <strong><em>recent_comments_style()</em></strong> belongs to the <strong><em>WP_Widget_Recent_Comments</em></strong> class, and we need a tiny bit more effort to get through to the object of that class.</p>
<p>The following snippet, suggested by <a href="http://twitter.com/nacin" rel="nofollow">Andrew Nacin</a> in a comment to the bug I opened up, does the job and works in WordPress 2.9.1:</p>
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre>add_action('widgets_init', 'my_remove_recent_comments_style');
function my_remove_recent_comments_style() {
	global $wp_widget_factory;
	remove_action('wp_head', array($wp_widget_factory-&gt;widgets['WP_Widget_Recent_Comments'], 'recent_comments_style'));
}</pre></td></tr></table></div>
<p>This code first gets access to the right object and then passes it to the <strong><em>remove_action()</em></strong> function, along with the right function name <strong><em>recent_comments_style</em></strong>. Stick it intoyour functions.php and it should do the trick.</p>
<p>And there you have it.</p>
<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=How+To+Remove+Inline+Hardcoded+Recent+Comments+Sidebar+Widget+Style+From+Your+Wo%5B..%5D+-+http://bit.ly/aafYTI&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://beerpla.net/2010/01/31/how-to-remove-inline-hardcoded-recent-comments-sidebar-widget-style-from-your-wordpress-theme/&amp;t=How+To+Remove+Inline+Hardcoded+Recent+Comments+Sidebar+Widget+Style+From+Your+WordPress+Theme" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://beerpla.net/2010/01/31/how-to-remove-inline-hardcoded-recent-comments-sidebar-widget-style-from-your-wordpress-theme/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-hackernews">
			<a href="http://news.ycombinator.com/submitlink?u=http://beerpla.net/2010/01/31/how-to-remove-inline-hardcoded-recent-comments-sidebar-widget-style-from-your-wordpress-theme/&amp;t=How+To+Remove+Inline+Hardcoded+Recent+Comments+Sidebar+Widget+Style+From+Your+WordPress+Theme" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://beerpla.net/2010/01/31/how-to-remove-inline-hardcoded-recent-comments-sidebar-widget-style-from-your-wordpress-theme/&amp;title=How+To+Remove+Inline+Hardcoded+Recent+Comments+Sidebar+Widget+Style+From+Your+WordPress+Theme" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://beerpla.net/2010/01/31/how-to-remove-inline-hardcoded-recent-comments-sidebar-widget-style-from-your-wordpress-theme/&amp;title=How+To+Remove+Inline+Hardcoded+Recent+Comments+Sidebar+Widget+Style+From+Your+WordPress+Theme" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://beerpla.net/2010/01/31/how-to-remove-inline-hardcoded-recent-comments-sidebar-widget-style-from-your-wordpress-theme/&amp;title=How+To+Remove+Inline+Hardcoded+Recent+Comments+Sidebar+Widget+Style+From+Your+WordPress+Theme" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://beerpla.net/2010/01/31/how-to-remove-inline-hardcoded-recent-comments-sidebar-widget-style-from-your-wordpress-theme/&amp;title=How+To+Remove+Inline+Hardcoded+Recent+Comments+Sidebar+Widget+Style+From+Your+WordPress+Theme" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22How%20To%20Remove%20Inline%20Hardcoded%20Recent%20Comments%20Sidebar%20Widget%20Style%20From%20Your%20WordPress%20Theme%22&amp;body=Link: http://beerpla.net/2010/01/31/how-to-remove-inline-hardcoded-recent-comments-sidebar-widget-style-from-your-wordpress-theme/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A The%20Problem%20%20If%20you%20use%20the%20Recent%20Comments%20sidebar%20widget%20in%20your%20Wordpress%20installation%2C%20it%27s%20possible%20that%20you%20want%20to%20customize%20this%20widget%27s%20style.%20%20You%20will%20quickly%20find%2C%20however%2C%20that%20as%20soon%20as%20you%20add%20the%20widget%20to%20your%20sidebar%2C%20it%20injects%20the%20following%20inline%2C%20hardcoded%20CSS%20into%20the%20contai" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
Similar Posts:<ul><li><a href="http://beerpla.net/2010/01/13/wordpress-plugin-development-how-to-include-css-and-javascript-conditionally-and-only-when-needed-by-the-posts/" rel="bookmark" title="January 13, 2010">[WordPress Plugin Development] How To Include CSS and JavaScript Conditionally And Only When Needed By The Posts</a></li>
<li><a href="http://beerpla.net/2008/03/29/beer-planet-upgraded-to-wordpress-25/" rel="bookmark" title="March 29, 2008">Beer Planet Upgraded To WordPress 2.5</a></li>
<li><a href="http://beerpla.net/2010/01/18/wordpress-developers-how-do-you-make-a-living-poll-discussion/" rel="bookmark" title="January 18, 2010">WordPress Developers &#8211; How Do You Make A Living [Poll + Discussion]?</a></li>
<li><a href="http://beerpla.net/2008/10/09/my-notes-on-learning-python-coming-from-perl/" rel="bookmark" title="October 9, 2008">My Notes On Learning Python Coming From Perl</a></li>
<li><a href="http://beerpla.net/2010/02/20/how-to-view-a-specific-svn-revision-in-your-browser/" rel="bookmark" title="February 20, 2010">How To View A Specific SVN Revision In Your Browser</a></li>
</ul><!-- Similar Posts took 15.091 ms --><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://beerpla.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://beerpla.net/2010/01/31/how-to-remove-inline-hardcoded-recent-comments-sidebar-widget-style-from-your-wordpress-theme/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
