{"id":320,"date":"2009-04-21T01:05:15","date_gmt":"2009-04-21T07:05:15","guid":{"rendered":"http:\/\/blog.edynamo.com\/?p=320"},"modified":"2009-05-17T09:09:09","modified_gmt":"2009-05-17T15:09:09","slug":"10-cool-wordpress-hacks","status":"publish","type":"post","link":"http:\/\/edynamo.com\/blog\/?p=320","title":{"rendered":"10 Cool WordPress Hacks"},"content":{"rendered":"<div id=\"attachment_340\" style=\"width: 250px\" class=\"wp-caption alignleft\"><a href=\"http:\/\/blog.edynamo.com\/?attachment_id=340\"><img aria-describedby=\"caption-attachment-340\" loading=\"lazy\" class=\"size-medium wp-image-340 \" title=\"wordpress\" src=\"http:\/\/blog.edynamo.com\/wp-content\/uploads\/wordpress-300x200.jpg\" alt=\"wordpress customization\" width=\"240\" height=\"160\" srcset=\"http:\/\/edynamo.com\/blog\/wp-content\/uploads\/wordpress-300x200.jpg 300w, http:\/\/edynamo.com\/blog\/wp-content\/uploads\/wordpress.jpg 455w\" sizes=\"(max-width: 240px) 100vw, 240px\" \/><\/a><p id=\"caption-attachment-340\" class=\"wp-caption-text\">customize your WordPress<\/p><\/div>\n<p>One of the reasons people love\u00a0<strong>WordPress<\/strong> so much is its great flexibility. You can change the software\u2019s appearance with themes. You can enhance its functionality with plug-ins. And, last but not least, you can totally unleash WordPress\u2019 power with hacks. Some time ago, we wrote a post showing<a href=\"http:\/\/www.smashingmagazine.com\/2009\/01\/07\/10-killer-wordpress-hacks\/\">10 Killer WordPress Hacks<\/a>.<\/p>\n<p>Today, let\u2019s do it again with\u00a0<strong>10 new and totally killer WordPress hacks<\/strong> to make your blog stand out from the crowd. As usual, we won\u2019t just list the hacks alone. In each entry, you\u2019ll find an explanation of the code as well as the kinds of problems that the hack solves.<\/p>\n<p>You may be interested in the following related posts:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.smashingmagazine.com\/2009\/03\/04\/15-useful-twitter-plugins-and-hacks-for-wordpress\/\">15 Useful Twitter Hacks and Plug-Ins For WordPress<\/a><\/li>\n<li><a href=\"http:\/\/www.smashingmagazine.com\/2009\/02\/02\/mastering-wordpress-shortcodes\/\">Mastering WordPress Shortcodes<\/a><\/li>\n<li><a href=\"http:\/\/www.smashingmagazine.com\/2009\/01\/26\/10-steps-to-protect-the-admin-area-in-wordpress\/\">10 Steps To Protect The Admin Area In WordPress<\/a><\/li>\n<li><a href=\"http:\/\/www.smashingmagazine.com\/2008\/12\/18\/8-useful-wordpress-sql-hacks\/\">8 Useful WordPress SQL Hacks<\/a><\/li>\n<li><a href=\"http:\/\/www.smashingmagazine.com\/2008\/12\/02\/10-useful-rss-hacks-for-wordpress\/\">10 Useful RSS-Tricks and Hacks For WordPress<\/a><\/li>\n<\/ul>\n<p><!--more--><\/p>\n<h3>\n<h3>1. Create TinyURLs On The Fly<\/h3>\n<p><img loading=\"lazy\" src=\"http:\/\/media2.smashingmagazine.com\/images\/wordpress-killer-hacks-tips\/sm1.jpg\" alt=\"Screenshot\" width=\"500\" height=\"202\" \/><\/p>\n<p><strong>The problem<\/strong>. Because Twitter has become a social media revolution, many bloggers and Twitter users enjoy sharing blog posts they have found and liked on Twitter. However, manually creating a TinyURL before tweeting can get a little tedious. As you probably know, Twitter can bring a lot of traffic to your blog, so it is in your interest to consistently provide short URLs to your readers.<\/p>\n<p><strong>The solution<\/strong>. To use this recipe, follow the simple steps below:<\/p>\n<ol>\n<li>Open your\u00a0<em>functions.php<\/em> file.<\/li>\n<li>Paste the following code in the file:\n<div class=\"dp-highlighter\">\n<div class=\"bar\">\n<div class=\"tools\"><a onclick=\"dp.sh.Toolbar.Command('ViewSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">view plain<\/a><a onclick=\"dp.sh.Toolbar.Command('CopyToClipboard',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">copy to clipboard<\/a><a onclick=\"dp.sh.Toolbar.Command('PrintSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">print<\/a><a onclick=\"dp.sh.Toolbar.Command('About',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">?<\/a><\/div>\n<\/div>\n<ol class=\"dp-c\">\n<li class=\"alt\"><span><span class=\"keyword\">function<\/span><span> getTinyUrl(<\/span><span class=\"vars\">$url<\/span><span>)\u00a0{ <\/span><\/span><\/li>\n<li><span> <span class=\"vars\">$tinyurl<\/span><span> = <\/span><span class=\"func\">file_get_contents<\/span><span>(<\/span><span class=\"string\">&#8220;http:\/\/tinyurl.com\/api-create.php?url=&#8221;<\/span><span>.<\/span><span class=\"vars\">$url<\/span><span>); <\/span><\/span><\/li>\n<li class=\"alt\"><span> <span class=\"keyword\">return<\/span><span> <\/span><span class=\"vars\">$tinyurl<\/span><span>; <\/span><\/span><\/li>\n<li><span>} <\/span><\/li>\n<\/ol>\n<\/div>\n<\/li>\n<li>Open your\u00a0<em>single.php<\/em> file and paste the following in the loop:\n<div class=\"dp-highlighter\">\n<div class=\"bar\">\n<div class=\"tools\"><a onclick=\"dp.sh.Toolbar.Command('ViewSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">view plain<\/a><a onclick=\"dp.sh.Toolbar.Command('CopyToClipboard',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">copy to clipboard<\/a><a onclick=\"dp.sh.Toolbar.Command('PrintSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">print<\/a><a onclick=\"dp.sh.Toolbar.Command('About',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">?<\/a><\/div>\n<\/div>\n<ol class=\"dp-c\">\n<li class=\"alt\"><span><span>&lt;?php <\/span><\/span><\/li>\n<li><span><span class=\"vars\">$turl<\/span><span> =\u00a0getTinyUrl(get_permalink(<\/span><span class=\"vars\">$post<\/span><span>-&gt;ID)); <\/span><\/span><\/li>\n<li class=\"alt\"><span><span class=\"func\">echo<\/span><span> <\/span><span class=\"string\">&#8216;Tiny\u00a0Url\u00a0for\u00a0this\u00a0post:\u00a0&lt;a\u00a0href=&#8221;&#8216;<\/span><span>.<\/span><span class=\"vars\">$turl<\/span><span>.<\/span><span class=\"string\">&#8216;&#8221;&gt;&#8217;<\/span><span>.<\/span><span class=\"vars\">$turl<\/span><span>.<\/span><span class=\"string\">&#8216;&lt;\/a&gt;&#8217;<\/span><span> <\/span><\/span><\/li>\n<li><span>?&gt; <\/span><\/li>\n<\/ol>\n<\/div>\n<\/li>\n<li>That\u2019s all you need. Each of your posts now has its own TinyURL, ready for tweeting!<\/li>\n<\/ol>\n<p><strong>Code explanation<\/strong>. The popular URL shortening service TinyURL provides a quick API that creates TinyURLs on the fly. When you pass a URL to\u00a0<em>http:\/\/tinyurl.com\/api-create.php<\/em>, the API immediately prints the related TinyURL on the screen.<\/p>\n<p>Using the PHP function file_get_contents(), we can get it and assign it to the $tinyurl variable. The last part of the code retrieves the post\u2019s permalink and passes it as a parameter to the getTinyUrl() function previously created.<\/p>\n<p>Source:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.wprecipes.com\/how-to-automatically-provide-tinyurls-for-your-wordpress-blog-posts\">How to: Automatically provide TinyURLs for your WordPress blog posts<\/a><\/li>\n<\/ul>\n<h3>2. List Upcoming Posts<\/h3>\n<p><img loading=\"lazy\" src=\"http:\/\/media2.smashingmagazine.com\/images\/wordpress-killer-hacks-tips\/sm8.jpg\" alt=\"Screenshot\" width=\"500\" height=\"217\" \/><\/p>\n<p><strong>The problem<\/strong>. If you often schedule posts to be published, how about displaying them in a list? This will make your readers look forward to what you\u2019re going to publish in a few days and can help you reach new RSS subscribers. Implementing this functionality on your WordPress blog isn\u2019t hard at all.<\/p>\n<p><strong>The solution<\/strong>. Nothing hard here. Just copy this code and paste it anywhere in your theme files.<\/p>\n<div class=\"dp-highlighter\">\n<div class=\"bar\">\n<div class=\"tools\"><a onclick=\"dp.sh.Toolbar.Command('ViewSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">view plain<\/a><a onclick=\"dp.sh.Toolbar.Command('CopyToClipboard',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">copy to clipboard<\/a><a onclick=\"dp.sh.Toolbar.Command('PrintSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">print<\/a><a onclick=\"dp.sh.Toolbar.Command('About',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">?<\/a><\/div>\n<\/div>\n<ol class=\"dp-c\">\n<li class=\"alt\"><span><span>&lt;div\u00a0id=<\/span><span class=\"string\">&#8220;zukunft&#8221;<\/span><span>&gt; <\/span><\/span><\/li>\n<li><span> &lt;div\u00a0id=<span class=\"string\">&#8220;zukunft_header&#8221;<\/span><span>&gt;&lt;p&gt;Future\u00a0events&lt;\/p&gt;&lt;\/div&gt; <\/span><\/span><\/li>\n<li class=\"alt\"><span> <\/span><\/li>\n<li><span> &lt;?php\u00a0query_posts(<span class=\"string\">&#8216;showposts=10&amp;post_status=future&#8217;<\/span><span>);\u00a0?&gt; <\/span><\/span><\/li>\n<li class=\"alt\"><span> &lt;?php\u00a0<span class=\"keyword\">if<\/span><span> (\u00a0have_posts()\u00a0)\u00a0: <\/span><span class=\"keyword\">while<\/span><span> (\u00a0have_posts()\u00a0)\u00a0:\u00a0the_post();\u00a0?&gt; <\/span><\/span><\/li>\n<li><span> &lt;div\u00a0&gt; <\/span><\/li>\n<li class=\"alt\"><span> &lt;p\u00a0<span class=\"keyword\">class<\/span><span>&gt;&lt;b&gt;&lt;?php\u00a0the_title();\u00a0?&gt;&lt;\/b&gt;&lt;?php\u00a0edit_post_link(<\/span><span class=\"string\">&#8216;e&#8217;<\/span><span>,<\/span><span class=\"string\">&#8216;\u00a0(&#8216;<\/span><span>,<\/span><span class=\"string\">&#8216;)&#8217;<\/span><span>);\u00a0?&gt;&lt;br\u00a0\/&gt; <\/span><\/span><\/li>\n<li><span> <\/span><\/li>\n<li class=\"alt\"><span> &lt;span\u00a0<span class=\"keyword\">class<\/span><span>=<\/span><span class=\"string\">&#8220;datetime&#8221;<\/span><span>&gt;&lt;?php\u00a0the_time(<\/span><span class=\"string\">&#8216;j.\u00a0F\u00a0Y&#8217;<\/span><span>);\u00a0?&gt;&lt;\/span&gt;&lt;\/p&gt; <\/span><\/span><\/li>\n<li><span> &lt;\/div&gt; <\/span><\/li>\n<li class=\"alt\"><span> &lt;?php\u00a0<span class=\"keyword\">endwhile<\/span><span>; <\/span><span class=\"keyword\">else<\/span><span>:\u00a0?&gt;&lt;p&gt;No\u00a0future\u00a0events\u00a0scheduled.&lt;\/p&gt;&lt;?php <\/span><span class=\"keyword\">endif<\/span><span>;\u00a0?&gt; <\/span><\/span><\/li>\n<li><span> <\/span><\/li>\n<li class=\"alt\"><span>&lt;\/div&gt; <\/span><\/li>\n<\/ol>\n<\/div>\n<p>Once you\u2019ve saved the file, your upcoming posts will be displayed on your blog.<\/p>\n<p><strong>Code explanation<\/strong>. This code use the super-powerful\u00a0<em>query_posts()<\/em> WordPress function, which allows you to take control of the WordPress loop.<\/p>\n<p>The parameter used is post_status, which allows you to get posts according to their status (published, draft, pending or future). The showposts parameter is also used to define how many items you\u2019d like to get. You can change the value of this parameter on line 4 to retrieve more or less than ten posts.<\/p>\n<p>Source:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.wprecipes.com\/how-to-list-future-posts\">How to: List future posts<\/a><\/li>\n<\/ul>\n<h3>3. Create A \u201cSend To Facebook\u201d Button<\/h3>\n<p><img loading=\"lazy\" src=\"http:\/\/media1.smashingmagazine.com\/images\/wordpress-killer-hacks-tips\/sm2.jpg\" alt=\"Screenshot\" width=\"500\" height=\"227\" \/><\/p>\n<p><strong>The problem<\/strong>. In the first hack, we noted that Twitter can bring a lot traffic to your blog. Another website that can boost your traffic stats easily is Facebook. In this hack, let\u2019s see how we can create a \u201cSend to Facebook\u201d button for your WordPress blog.<\/p>\n<p><strong>The solution<\/strong>.<\/p>\n<ol>\n<li>Open the\u00a0<em>single.php<\/em> file in your theme.<\/li>\n<li>Paste the following code in the loop:\n<div class=\"dp-highlighter\">\n<div class=\"bar\">\n<div class=\"tools\"><a onclick=\"dp.sh.Toolbar.Command('ViewSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">view plain<\/a><a onclick=\"dp.sh.Toolbar.Command('CopyToClipboard',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">copy to clipboard<\/a><a onclick=\"dp.sh.Toolbar.Command('PrintSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">print<\/a><a onclick=\"dp.sh.Toolbar.Command('About',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">?<\/a><\/div>\n<\/div>\n<ol class=\"dp-c\">\n<li class=\"alt\"><span><span>&lt;a\u00a0href=<\/span><span class=\"string\">&#8220;http:\/\/www.facebook.com\/sharer.php?u=&lt;?php\u00a0the_permalink();?&gt;&amp;t=&lt;?php\u00a0the_title();\u00a0?&gt;&#8221;<\/span><span> target=<\/span><span class=\"string\">&#8220;blank&#8221;<\/span><span>&gt;Share\u00a0on\u00a0Facebook&lt;\/a&gt; <\/span><\/span><\/li>\n<\/ol>\n<\/div>\n<\/li>\n<li>Alternatively, you could use the getTinyUrl() function to send a short URL to Facebook:\n<div class=\"dp-highlighter\">\n<div class=\"bar\">\n<div class=\"tools\"><a onclick=\"dp.sh.Toolbar.Command('ViewSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">view plain<\/a><a onclick=\"dp.sh.Toolbar.Command('CopyToClipboard',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">copy to clipboard<\/a><a onclick=\"dp.sh.Toolbar.Command('PrintSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">print<\/a><a onclick=\"dp.sh.Toolbar.Command('About',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">?<\/a><\/div>\n<\/div>\n<ol class=\"dp-c\">\n<li class=\"alt\"><span><span>&lt;?php <\/span><span class=\"vars\">$turl<\/span><span> =\u00a0getTinyUrl(get_permalink(<\/span><span class=\"vars\">$post<\/span><span>-&gt;ID));\u00a0?&gt; <\/span><\/span><\/li>\n<li><span>&lt;a\u00a0href=<span class=\"string\">&#8220;http:\/\/www.facebook.com\/sharer.php?u=&lt;?php\u00a0echo\u00a0$turl;?&gt;&amp;t=&lt;?php\u00a0the_title();\u00a0?&gt;&#8221;<\/span><span> target=<\/span><span class=\"string\">&#8220;blank&#8221;<\/span><span>&gt;Share\u00a0on\u00a0Facebook&lt;\/a&gt; <\/span><\/span><\/li>\n<\/ol>\n<\/div>\n<\/li>\n<li>That\u2019s all. Your readers will now be able to share your blog post on Facebook with their friends!<\/li>\n<\/ol>\n<p><strong>Code explanation<\/strong>. This useful hack is very easy to understand: the only thing we do here is retrieve the post\u2019s permalink and title and send them as parameters to\u00a0<em>http:\/\/www.facebook.com\/sharer.php<\/em>.<\/p>\n<p>In the alternative method, we used the getTinyUrl() function (created in the previous hack) to send a short URL instead of the post\u2019s permalink.<\/p>\n<p>Source:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.wprecipes.com\/how-to-add-a-share-on-facebook-link-to-your-wordpress-blog\">How to: Add a \u201cShare on Facebook\u201d link to your WordPress blog<\/a><\/li>\n<\/ul>\n<h3>4. Create A Maintenance Page For Your WordPress Blog<\/h3>\n<p><img loading=\"lazy\" src=\"http:\/\/media1.smashingmagazine.com\/images\/wordpress-killer-hacks-tips\/sm3.jpg\" alt=\"Screenshot\" width=\"500\" height=\"222\" \/><\/p>\n<p><strong>The problem<\/strong>. One thing I really like about Drupal is the option to temporarily redirect visitors to a maintenance page. Sadly, WordPress doesn\u2019t have this feature. When you upgrade your blog, switch themes or make design changes, you may not want your visitors to see your blog as it is being tweaked, especially if it has design or code problems or, even worse, security gaps.<\/p>\n<p><strong>The solution<\/strong>. To solve this problem, we use the power of the\u00a0<em>.htaccess<\/em> file. Just follow the steps below to get started.<\/p>\n<ol>\n<li>Create your maintenance page. A simple WordPress page is generally sufficient.<\/li>\n<li>Find your\u00a0<em>.htaccess<\/em> file (located at the root of your WordPress installation) and\u00a0<strong>create a back-up<\/strong>.<\/li>\n<li>Open your\u00a0<em>.htaccess<\/em> file for editing.<\/li>\n<li>Paste the following code:\n<div class=\"dp-highlighter\">\n<div class=\"bar\">\n<div class=\"tools\"><a onclick=\"dp.sh.Toolbar.Command('ViewSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">view plain<\/a><a onclick=\"dp.sh.Toolbar.Command('CopyToClipboard',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">copy to clipboard<\/a><a onclick=\"dp.sh.Toolbar.Command('PrintSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">print<\/a><a onclick=\"dp.sh.Toolbar.Command('About',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">?<\/a><\/div>\n<\/div>\n<ol class=\"dp-c\">\n<li class=\"alt\"><span><span>RewriteEngine\u00a0on <\/span><\/span><\/li>\n<li><span>RewriteCond\u00a0%{REQUEST_URI}\u00a0!\/maintenance.html$ <\/span><\/li>\n<li class=\"alt\"><span>RewriteCond\u00a0%{REMOTE_ADDR}\u00a0!^123\\.123\\.123\\.123 <\/span><\/li>\n<li><span>RewriteRule\u00a0$\u00a0\/maintenance.html\u00a0[R=302,L] <\/span><\/li>\n<\/ol>\n<\/div>\n<\/li>\n<li>Replace 123\\.123\\.123\\.123 on line 3 with your IP address (<a href=\"http:\/\/www.ip-adress.com\/\">Don\u2019t know it?<\/a>). Make sure to use the same syntax.<\/li>\n<li>Now, all visitors except you will be redirected to your maintenance page.<\/li>\n<li>Once you\u2019re done tweaking, upgrading, theme switching or whatever, re-open your\u00a0<em>.htaccess<\/em>file and remove (or comment out) the redirection code.<\/li>\n<\/ol>\n<p><strong>Code explanation<\/strong>. The\u00a0<em>.htaccess<\/em> file, which controls the Apache Web server, is very useful for these kinds of tasks.<\/p>\n<p>In this example, we state that any visitor who has an IP different from 123.123.123.123 (which doesn\u2019t request\u00a0<em>maintenance.html<\/em>) should be redirected to\u00a0<em>maintenance.html<\/em>.<\/p>\n<p>By replacing 123.123.123.123 with your own IP address, you make sure you\u2019re still allowed to browse your blog normally, while others are redirected to\u00a0<em>maintenance.html<\/em>.<\/p>\n<p>Source:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.catswhocode.com\/blog\/10-awesome-htaccess-hacks-for-wordpress\">10 awesome .htaccess hacks for WordPress<\/a><\/li>\n<\/ul>\n<h3>5. Display Related Posts Without A Plug-In<\/h3>\n<p><img loading=\"lazy\" src=\"http:\/\/media2.smashingmagazine.com\/images\/wordpress-killer-hacks-tips\/sm4.jpg\" alt=\"Screenshot\" width=\"500\" height=\"203\" \/><\/p>\n<p><strong>The problem<\/strong>. One well-known way of keeping visitors on your blog longer and helping them discover news posts is to display, usually at the end of the article, a list of related content.<\/p>\n<p>Many plug-ins will do this job, but why not super-charge your theme by integrating this functionality by default?<\/p>\n<p><strong>The solution<\/strong>.<\/p>\n<ol>\n<li>Open the\u00a0<em>single.php<\/em> file in your theme.<\/li>\n<li>Paste the following code in the loop:\n<div class=\"dp-highlighter\">\n<div class=\"bar\">\n<div class=\"tools\"><a onclick=\"dp.sh.Toolbar.Command('ViewSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">view plain<\/a><a onclick=\"dp.sh.Toolbar.Command('CopyToClipboard',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">copy to clipboard<\/a><a onclick=\"dp.sh.Toolbar.Command('PrintSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">print<\/a><a onclick=\"dp.sh.Toolbar.Command('About',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">?<\/a><\/div>\n<\/div>\n<ol class=\"dp-c\">\n<li class=\"alt\"><span><span>&lt;?php <\/span><\/span><\/li>\n<li><span><span class=\"comment\">\/\/for\u00a0use\u00a0in\u00a0the\u00a0loop,\u00a0list\u00a05\u00a0post\u00a0titles\u00a0related\u00a0to\u00a0first\u00a0tag\u00a0on\u00a0current\u00a0post<\/span><span> <\/span><\/span><\/li>\n<li class=\"alt\"><span><span class=\"vars\">$tags<\/span><span> =\u00a0wp_get_post_tags(<\/span><span class=\"vars\">$post<\/span><span>-&gt;ID); <\/span><\/span><\/li>\n<li><span><span class=\"keyword\">if<\/span><span> (<\/span><span class=\"vars\">$tags<\/span><span>)\u00a0{ <\/span><\/span><\/li>\n<li class=\"alt\"><span> <span class=\"func\">echo<\/span><span> <\/span><span class=\"string\">&#8216;Related\u00a0Posts&#8217;<\/span><span>; <\/span><\/span><\/li>\n<li><span> <span class=\"vars\">$first_tag<\/span><span> = <\/span><span class=\"vars\">$tags<\/span><span>[0]-&gt;term_id; <\/span><\/span><\/li>\n<li class=\"alt\"><span> <span class=\"vars\">$args<\/span><span>=<\/span><span class=\"keyword\">array<\/span><span>( <\/span><\/span><\/li>\n<li><span> <span class=\"string\">&#8216;tag__in&#8217;<\/span><span> =&gt; <\/span><span class=\"keyword\">array<\/span><span>(<\/span><span class=\"vars\">$first_tag<\/span><span>), <\/span><\/span><\/li>\n<li class=\"alt\"><span> <span class=\"string\">&#8216;post__not_in&#8217;<\/span><span> =&gt; <\/span><span class=\"keyword\">array<\/span><span>(<\/span><span class=\"vars\">$post<\/span><span>-&gt;ID), <\/span><\/span><\/li>\n<li><span> <span class=\"string\">&#8216;showposts&#8217;<\/span><span>=&gt;5, <\/span><\/span><\/li>\n<li class=\"alt\"><span> <span class=\"string\">&#8216;caller_get_posts&#8217;<\/span><span>=&gt;1 <\/span><\/span><\/li>\n<li><span> ); <\/span><\/li>\n<li class=\"alt\"><span> <span class=\"vars\">$my_query<\/span><span> = <\/span><span class=\"keyword\">new<\/span><span> WP_Query(<\/span><span class=\"vars\">$args<\/span><span>); <\/span><\/span><\/li>\n<li><span> <span class=\"keyword\">if<\/span><span>( <\/span><span class=\"vars\">$my_query<\/span><span>-&gt;have_posts()\u00a0)\u00a0{ <\/span><\/span><\/li>\n<li class=\"alt\"><span> <span class=\"keyword\">while<\/span><span> (<\/span><span class=\"vars\">$my_query<\/span><span>-&gt;have_posts())\u00a0: <\/span><span class=\"vars\">$my_query<\/span><span>-&gt;the_post();\u00a0?&gt; <\/span><\/span><\/li>\n<li><span> &lt;p&gt;&lt;a\u00a0href=<span class=\"string\">&#8220;&lt;?php\u00a0the_permalink()\u00a0?&gt;&#8221;<\/span><span> rel=<\/span><span class=\"string\">&#8220;bookmark&#8221;<\/span><span> title=<\/span><span class=\"string\">&#8220;Permanent\u00a0Link\u00a0to\u00a0&lt;?php\u00a0the_title_attribute();\u00a0?&gt;&#8221;<\/span><span>&gt;&lt;?php\u00a0the_title();\u00a0?&gt;&lt;\/a&gt;&lt;\/p&gt; <\/span><\/span><\/li>\n<li class=\"alt\"><span> &lt;?php <\/span><\/li>\n<li><span> <span class=\"keyword\">endwhile<\/span><span>; <\/span><\/span><\/li>\n<li class=\"alt\"><span> } <\/span><\/li>\n<li><span>} <\/span><\/li>\n<li class=\"alt\"><span>?&gt; <\/span><\/li>\n<\/ol>\n<\/div>\n<\/li>\n<li>Save the file, and then have a look at your blog: related posts are automatically displayed!<\/li>\n<\/ol>\n<p><strong>Code explanation<\/strong>. This hack uses tags to retrieve related posts. The first thing it does is get the post\u2019s tags. If a post has tags, the first one is extracted and used in a query that retrieves posts with the same tag.<\/p>\n<p>By default, this code displays up to five related posts. To change this number, simply edit line 9 of the code.<\/p>\n<p>Source:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.wprecipes.com\/how-to-show-related-posts-without-a-plugin\">How to: Show related posts without a plug-in<\/a><\/li>\n<\/ul>\n<h3>6. Automatically Retrieve The First Image From Posts On Your Home Page<\/h3>\n<p><img loading=\"lazy\" src=\"http:\/\/media2.smashingmagazine.com\/images\/wordpress-killer-hacks-tips\/sm5.jpg\" alt=\"Screenshot\" width=\"500\" height=\"230\" \/><\/p>\n<p><strong>The problem<\/strong>. Many WordPress users use custom fields to display a thumbnail on their blog home page. Of course, this is a nice solution, but how about automatically retrieving the first image from a post and using it as a thumbnail?<\/p>\n<p><strong>The solution<\/strong>. This hack is quite easy to implement:<\/p>\n<ol>\n<li>Open the\u00a0<em>functions.php<\/em> file in your theme.<\/li>\n<li>Paste this code in. Don\u2019t forget to specify a default image on line 10 (in case a post of yours does not have an image).\n<div class=\"dp-highlighter\">\n<div class=\"bar\">\n<div class=\"tools\"><a onclick=\"dp.sh.Toolbar.Command('ViewSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">view plain<\/a><a onclick=\"dp.sh.Toolbar.Command('CopyToClipboard',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">copy to clipboard<\/a><a onclick=\"dp.sh.Toolbar.Command('PrintSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">print<\/a><a onclick=\"dp.sh.Toolbar.Command('About',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">?<\/a><\/div>\n<\/div>\n<ol class=\"dp-c\">\n<li class=\"alt\"><span><span class=\"keyword\">function<\/span><span> catch_that_image()\u00a0{ <\/span><\/span><\/li>\n<li><span> <span class=\"keyword\">global<\/span><span> <\/span><span class=\"vars\">$post<\/span><span>, <\/span><span class=\"vars\">$posts<\/span><span>; <\/span><\/span><\/li>\n<li class=\"alt\"><span> <span class=\"vars\">$first_img<\/span><span> = <\/span><span class=\"string\">&#8221;<\/span><span>; <\/span><\/span><\/li>\n<li><span> ob_start(); <\/span><\/li>\n<li class=\"alt\"><span> ob_end_clean(); <\/span><\/li>\n<li><span> <span class=\"vars\">$output<\/span><span> =\u00a0preg_match_all(<\/span><span class=\"string\">&#8216;\/&lt;img.+src=[\\'&#8221;]([^\\'&#8221;]+)[\\'&#8221;].*&gt;\/i&#8217;<\/span><span>, <\/span><span class=\"vars\">$post<\/span><span>-&gt;post_content, <\/span><span class=\"vars\">$matches<\/span><span>); <\/span><\/span><\/li>\n<li class=\"alt\"><span> <span class=\"vars\">$first_img<\/span><span> = <\/span><span class=\"vars\">$matches<\/span><span> [1]\u00a0[0]; <\/span><\/span><\/li>\n<li><span> <\/span><\/li>\n<li class=\"alt\"><span> <span class=\"keyword\">if<\/span><span>(<\/span><span class=\"keyword\">empty<\/span><span class=\"func\">empty<\/span><span>(<\/span><span class=\"vars\">$first_img<\/span><span>)){ <\/span><span class=\"comment\">\/\/Defines\u00a0a\u00a0default\u00a0image<\/span><span> <\/span><\/span><\/li>\n<li><span> <span class=\"vars\">$first_img<\/span><span> = <\/span><span class=\"string\">&#8220;\/images\/default.jpg&#8221;<\/span><span>; <\/span><\/span><\/li>\n<li class=\"alt\"><span> } <\/span><\/li>\n<li><span> <span class=\"keyword\">return<\/span><span> <\/span><span class=\"vars\">$first_img<\/span><span>; <\/span><\/span><\/li>\n<li class=\"alt\"><span>} <\/span><\/li>\n<\/ol>\n<\/div>\n<\/li>\n<li>Save the\u00a0<em>functions.php<\/em> file.<\/li>\n<li>On your blog home page (<em>index.php<\/em>), call the function this way to get the URL of the first image from the post:\n<div class=\"dp-highlighter\">\n<div class=\"bar\">\n<div class=\"tools\"><a onclick=\"dp.sh.Toolbar.Command('ViewSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">view plain<\/a><a onclick=\"dp.sh.Toolbar.Command('CopyToClipboard',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">copy to clipboard<\/a><a onclick=\"dp.sh.Toolbar.Command('PrintSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">print<\/a><a onclick=\"dp.sh.Toolbar.Command('About',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">?<\/a><\/div>\n<\/div>\n<ol class=\"dp-c\">\n<li class=\"alt\"><span><span>&lt;?php <\/span><span class=\"func\">echo<\/span><span> catch_that_image()\u00a0?&gt; <\/span><\/span><\/li>\n<\/ol>\n<\/div>\n<\/li>\n<\/ol>\n<p><strong>Code explanation<\/strong>. The function uses the global variable $post to parse the post\u2019s content with a regular expression. If an image is found, its URL is returned by the function. If not, the default image URL is returned.<\/p>\n<p>Source:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.wprecipes.com\/how-to-get-the-first-image-from-the-post-and-display-it\">How to: Get the first image from the post and display it<\/a><\/li>\n<li><a href=\"http:\/\/wordpress.org\/support\/topic\/246893\">Retreive first image from post<\/a><\/li>\n<\/ul>\n<h3>7. Resize Images On The Fly<\/h3>\n<p><img loading=\"lazy\" src=\"http:\/\/media1.smashingmagazine.com\/images\/wordpress-killer-hacks-tips\/sm6.jpg\" alt=\"Screenshot\" width=\"500\" height=\"161\" \/><\/p>\n<p><strong>The problem<\/strong>. When you use thumbnails on your blog\u2019s home page or even images in posts, having to manually resize them is boring and wastes a lot of time. So, why not use the power of PHP to do it?<\/p>\n<p><strong>The solution<\/strong>. To achieve this hack, just follow these simple steps:<\/p>\n<ol>\n<li>Get\u00a0<a href=\"http:\/\/timthumb.googlecode.com\/svn\/trunk\/timthumb.php\">this script<\/a> and save it on your computer (I\u2019ll assume you\u2019ve named it\u00a0<em>timthumb.php<\/em>).<\/li>\n<li>Use an FTP program to connect to your server and create a new directory called\u00a0<em>scripts<\/em>. Upload the\u00a0<em>timthumb.php<\/em> file to it.<\/li>\n<li>Once done, you can display images like so:\n<div class=\"dp-highlighter\">\n<div class=\"bar\">\n<div class=\"tools\"><a onclick=\"dp.sh.Toolbar.Command('ViewSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">view plain<\/a><a onclick=\"dp.sh.Toolbar.Command('CopyToClipboard',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">copy to clipboard<\/a><a onclick=\"dp.sh.Toolbar.Command('PrintSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">print<\/a><a onclick=\"dp.sh.Toolbar.Command('About',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">?<\/a><\/div>\n<\/div>\n<ol class=\"dp-c\">\n<li class=\"alt\"><span><span>&lt;img\u00a0src=<\/span><span class=\"string\">&#8220;\/scripts\/timthumb.php?src=\/images\/whatever.jpg&amp;h=150&amp;w=150&amp;zc=1&#8221;<\/span><span> alt=<\/span><span class=\"string\">&#8220;Screenshot&#8221;<\/span><span> \/&gt; <\/span><\/span><\/li>\n<\/ol>\n<\/div>\n<p>In other words, you just call the\u00a0<em>timthumb.php<\/em> file and pass your image as a parameter. The same goes for your desired width and height.<\/li>\n<\/ol>\n<p><strong>Code explanation<\/strong>. The\u00a0<em>timthumb.php<\/em> script use the PHP GD library, which allows you to manipulate images dynamically with PHP. GD is installed by default on all servers running PHP5. If you\u2019re not running PHP5, you\u2019ll have to check if GD is installed before using this script.<\/p>\n<p>The\u00a0<em>timthumb.php<\/em> file gets the parameters you\u2019ve passed to it (image URL, width and height) and uses it to create a new image with your stated dimensions. Once that\u2019s done, the image is returned to you.<\/p>\n<p>Source:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.darrenhoyt.com\/2008\/04\/02\/timthumb-php-script-released\/\">TimThumb PHP script released<\/a><\/li>\n<li><a href=\"http:\/\/www.wprecipes.com\/how-to-resize-images-on-the-fly\">How to: Resize images on the fly<\/a><\/li>\n<\/ul>\n<h3>8. Get Your Most Popular Posts Without A Plug-In<\/h3>\n<p><img loading=\"lazy\" src=\"http:\/\/media1.smashingmagazine.com\/images\/wordpress-killer-hacks-tips\/sm7.jpg\" alt=\"Screenshot\" width=\"500\" height=\"196\" \/><\/p>\n<p><strong>The problem<\/strong>. Displaying your most popular posts is a good way to make visitors stay longer on your blog, as is displaying related posts. Many great plug-ins can list your most popular posts, but again, why use a plug-in when you can simply hack your WordPress theme to do it automatically?<\/p>\n<p><strong>The solution<\/strong>. Just paste the following code anywhere in your theme files (for example, in\u00a0<em>sidebar.php<\/em>). To change the number of displayed posts, simply change the \u201c5\u2033 on line 3 to your desired number.<\/p>\n<div class=\"dp-highlighter\">\n<div class=\"bar\">\n<div class=\"tools\"><a onclick=\"dp.sh.Toolbar.Command('ViewSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">view plain<\/a><a onclick=\"dp.sh.Toolbar.Command('CopyToClipboard',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">copy to clipboard<\/a><a onclick=\"dp.sh.Toolbar.Command('PrintSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">print<\/a><a onclick=\"dp.sh.Toolbar.Command('About',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">?<\/a><\/div>\n<\/div>\n<ol class=\"dp-c\">\n<li class=\"alt\"><span><span>&lt;h2&gt;Popular\u00a0Posts&lt;\/h2&gt; <\/span><\/span><\/li>\n<li><span>&lt;ul&gt; <\/span><\/li>\n<li class=\"alt\"><span>&lt;?php\u00a0<span class=\"vars\">$result<\/span><span> = <\/span><span class=\"vars\">$wpdb<\/span><span>-&gt;get_results(<\/span><span class=\"string\">&#8220;SELECT\u00a0comment_count,ID,post_title\u00a0FROM\u00a0$wpdb-&gt;posts\u00a0ORDER\u00a0BY\u00a0comment_count\u00a0DESC\u00a0LIMIT\u00a00\u00a0,\u00a05&#8221;<\/span><span>); <\/span><\/span><\/li>\n<li><span><span class=\"keyword\">foreach<\/span><span> (<\/span><span class=\"vars\">$result<\/span><span> <\/span><span class=\"keyword\">as<\/span><span> <\/span><span class=\"vars\">$post<\/span><span>)\u00a0{ <\/span><\/span><\/li>\n<li class=\"alt\"><span>setup_postdata(<span class=\"vars\">$post<\/span><span>); <\/span><\/span><\/li>\n<li><span><span class=\"vars\">$postid<\/span><span> = <\/span><span class=\"vars\">$post<\/span><span>-&gt;ID; <\/span><\/span><\/li>\n<li class=\"alt\"><span><span class=\"vars\">$title<\/span><span> = <\/span><span class=\"vars\">$post<\/span><span>-&gt;post_title; <\/span><\/span><\/li>\n<li><span><span class=\"vars\">$commentcount<\/span><span> = <\/span><span class=\"vars\">$post<\/span><span>-&gt;comment_count; <\/span><\/span><\/li>\n<li class=\"alt\"><span><span class=\"keyword\">if<\/span><span> (<\/span><span class=\"vars\">$commentcount<\/span><span> !=\u00a00)\u00a0{\u00a0?&gt; <\/span><\/span><\/li>\n<li><span> <\/span><\/li>\n<li class=\"alt\"><span>&lt;li&gt;&lt;a\u00a0href=<span class=\"string\">&#8220;&lt;?php\u00a0echo\u00a0get_permalink($postid);\u00a0?&gt;&#8221;<\/span><span> title=<\/span><span class=\"string\">&#8220;&lt;?php\u00a0echo\u00a0$title\u00a0?&gt;&#8221;<\/span><span>&gt; <\/span><\/span><\/li>\n<li><span>&lt;?php\u00a0<span class=\"func\">echo<\/span><span> <\/span><span class=\"vars\">$title<\/span><span> ?&gt;&lt;\/a&gt;\u00a0{&lt;?php <\/span><span class=\"func\">echo<\/span><span> <\/span><span class=\"vars\">$commentcount<\/span><span> ?&gt;}&lt;\/li&gt; <\/span><\/span><\/li>\n<li class=\"alt\"><span>&lt;?php\u00a0}\u00a0}\u00a0?&gt; <\/span><\/li>\n<li><span> <\/span><\/li>\n<li class=\"alt\"><span>&lt;\/ul&gt; <\/span><\/li>\n<\/ol>\n<\/div>\n<p><strong>Code explanation<\/strong>. This code executes an SQL query to the WordPress database, using the $wpdb object, to get a list of the five posts with the most comments. The results are then wrapped in an unordered HTML list and displayed on screen.<\/p>\n<p>Source:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.problogdesign.com\/wordpress\/create-your-own-popular-posts-page\/\">Create your own popular posts page<\/a><\/li>\n<\/ul>\n<h3>9. Highlight Searched Text In Search Results<\/h3>\n<p><img loading=\"lazy\" src=\"http:\/\/media2.smashingmagazine.com\/images\/wordpress-killer-hacks-tips\/sm9.jpg\" alt=\"Screenshot\" width=\"500\" height=\"93\" \/><\/p>\n<p><strong>The problem<\/strong>. The WordPress search engine system is often criticized for not being powerful enough. One of its weakest points in my opinion is that searched text is not easily distinguishable from the rest of the text. Let\u2019s solve that!<\/p>\n<p><strong>The solution<\/strong>.<\/p>\n<ol>\n<li>Open your\u00a0<em>search.php<\/em> file and find the the_title() function.<\/li>\n<li>Replace it with the following:\n<div class=\"dp-highlighter\">\n<div class=\"bar\">\n<div class=\"tools\"><a onclick=\"dp.sh.Toolbar.Command('ViewSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">view plain<\/a><a onclick=\"dp.sh.Toolbar.Command('CopyToClipboard',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">copy to clipboard<\/a><a onclick=\"dp.sh.Toolbar.Command('PrintSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">print<\/a><a onclick=\"dp.sh.Toolbar.Command('About',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">?<\/a><\/div>\n<\/div>\n<ol class=\"dp-c\">\n<li class=\"alt\"><span><span class=\"func\">echo<\/span><span> <\/span><span class=\"vars\">$title<\/span><span>; <\/span><\/span><\/li>\n<\/ol>\n<\/div>\n<\/li>\n<li>Now, just before the modified line, add this code:\n<div class=\"dp-highlighter\">\n<div class=\"bar\">\n<div class=\"tools\"><a onclick=\"dp.sh.Toolbar.Command('ViewSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">view plain<\/a><a onclick=\"dp.sh.Toolbar.Command('CopyToClipboard',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">copy to clipboard<\/a><a onclick=\"dp.sh.Toolbar.Command('PrintSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">print<\/a><a onclick=\"dp.sh.Toolbar.Command('About',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">?<\/a><\/div>\n<\/div>\n<ol class=\"dp-c\">\n<li class=\"alt\"><span><span>&lt;?php <\/span><\/span><\/li>\n<li><span> <span class=\"vars\">$title<\/span><span> =\u00a0get_the_title(); <\/span><\/span><\/li>\n<li class=\"alt\"><span> <span class=\"vars\">$keys<\/span><span>= <\/span><span class=\"func\">explode<\/span><span>(<\/span><span class=\"string\">&#8221;\u00a0&#8220;<\/span><span>,<\/span><span class=\"vars\">$s<\/span><span>); <\/span><\/span><\/li>\n<li><span> <span class=\"vars\">$title<\/span><span> =\u00a0preg_replace(<\/span><span class=\"string\">&#8216;\/(&#8216;<\/span><span>.implode(<\/span><span class=\"string\">&#8216;|&#8217;<\/span><span>, <\/span><span class=\"vars\">$keys<\/span><span>)\u00a0.<\/span><span class=\"string\">&#8216;)\/iu&#8217;<\/span><span>, <\/span><\/span><\/li>\n<li class=\"alt\"><span> <span class=\"string\">&#8216;&lt;strong\u00a0class=&#8221;search-excerpt&#8221;&gt;\\0&lt;\/strong&gt;&#8217;<\/span><span>, <\/span><\/span><\/li>\n<li><span> <span class=\"vars\">$title<\/span><span>); <\/span><\/span><\/li>\n<li class=\"alt\"><span>?&gt; <\/span><\/li>\n<\/ol>\n<\/div>\n<\/li>\n<li>Save the\u00a0<em>search.php<\/em> file and open\u00a0<em>style.css<\/em>. Add the following line to it:\n<div class=\"dp-highlighter\">\n<div class=\"bar\">\n<div class=\"tools\"><a onclick=\"dp.sh.Toolbar.Command('ViewSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">view plain<\/a><a onclick=\"dp.sh.Toolbar.Command('CopyToClipboard',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">copy to clipboard<\/a><a onclick=\"dp.sh.Toolbar.Command('PrintSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">print<\/a><a onclick=\"dp.sh.Toolbar.Command('About',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">?<\/a><\/div>\n<\/div>\n<ol class=\"dp-c\">\n<li class=\"alt\"><span><span>strong.search-excerpt\u00a0{\u00a0background:\u00a0yellow;\u00a0} <\/span><\/span><\/li>\n<\/ol>\n<\/div>\n<\/li>\n<\/ol>\n<p>That\u2019s all. Better, isn\u2019t it?<\/p>\n<p><strong>Code explanation<\/strong>. Once again, regular expressions are a lifesaver. The regexp parses the $s content ($s is the variable containing the searched text) and automatically adds a\u00a0<em>&lt;strong class=\u201dsearch-excerpt\u201d&gt;<\/em> element around any occurrences of $s.<\/p>\n<p>Then, you simply modify your\u00a0<em>style.css<\/em> file to give searched text a special style and make it more visible to your readers.<\/p>\n<p>Sources:<\/p>\n<ul>\n<li><a href=\"http:\/\/yoast.com\/wordpress-search\/\">Make WordPress\u2019 search function suck less.<\/a><\/li>\n<li><a href=\"http:\/\/www.wprecipes.com\/how-to-enlight-searched-text-in-search-results\">How to: Highlight searched text in search results<\/a><\/li>\n<\/ul>\n<h3>10. Disable Widgetized Areas Without Editing Theme Files<\/h3>\n<p><img loading=\"lazy\" src=\"http:\/\/media2.smashingmagazine.com\/images\/wordpress-killer-hacks-tips\/sm10.jpg\" alt=\"Screenshot\" width=\"500\" height=\"255\" \/><\/p>\n<p><strong>The problem<\/strong>. Widgets are very useful, but sometimes you don\u2019t need them on a particular page or post. Sure, you can create a page template for a particular page or even remove the widgetized zone from the code, but a much better and more elegant solution exists.<\/p>\n<p><strong>The solution<\/strong>. To do this, simply add the following code to your\u00a0<em>functions.php<\/em> file:<\/p>\n<div class=\"dp-highlighter\">\n<div class=\"bar\">\n<div class=\"tools\"><a onclick=\"dp.sh.Toolbar.Command('ViewSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">view plain<\/a><a onclick=\"dp.sh.Toolbar.Command('CopyToClipboard',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">copy to clipboard<\/a><a onclick=\"dp.sh.Toolbar.Command('PrintSource',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">print<\/a><a onclick=\"dp.sh.Toolbar.Command('About',this);return false;\" href=\"http:\/\/www.smashingmagazine.com\/2009\/04\/15\/10-exceptional-wordpress-hacks\/#\">?<\/a><\/div>\n<\/div>\n<ol class=\"dp-c\">\n<li class=\"alt\"><span><span>&lt;?php <\/span><\/span><\/li>\n<li><span>add_filter(\u00a0<span class=\"string\">&#8216;sidebars_widgets&#8217;<\/span><span>, <\/span><span class=\"string\">&#8216;disable_all_widgets&#8217;<\/span><span> ); <\/span><\/span><\/li>\n<li class=\"alt\"><span> <\/span><\/li>\n<li><span><span class=\"keyword\">function<\/span><span> disable_all_widgets( <\/span><span class=\"vars\">$sidebars_widgets<\/span><span> )\u00a0{ <\/span><\/span><\/li>\n<li class=\"alt\"><span> <span class=\"keyword\">if<\/span><span> (\u00a0is_home()\u00a0) <\/span><\/span><\/li>\n<li><span> <span class=\"vars\">$sidebars_widgets<\/span><span> = <\/span><span class=\"keyword\">array<\/span><span>(\u00a0false\u00a0); <\/span><\/span><\/li>\n<li class=\"alt\"><span> <span class=\"keyword\">return<\/span><span> <\/span><span class=\"vars\">$sidebars_widgets<\/span><span>; <\/span><\/span><\/li>\n<li><span>} <\/span><\/li>\n<li class=\"alt\"><span>?&gt; <\/span><\/li>\n<\/ol>\n<\/div>\n<p><strong>Code explanation<\/strong>. This code first adds a filter to the sidebars_widgets WordPress function. Now every time WordPress tries to execute this function, it will execute the disable_all_widgets function we just created.<\/p>\n<p>The disable_all_widgets function uses WordPress conditional tags (in this example, is_home(), but you can use any conditional tag) to disable all widgets if a visitor is on a particular page or post.<\/p>\n<p>Source:<\/p>\n<ul>\n<li><a href=\"http:\/\/justintadlock.com\/archives\/2009\/03\/06\/disable-widget-areas-without-touching-theme-templates\">Disable widget areas (sidebars) without touching theme templates<\/a><\/li>\n<\/ul>\n<\/h3>\n","protected":false},"excerpt":{"rendered":"<p>One of the reasons people love WordPress so much is its great flexibility. You can change the software\u2019s appearance with themes. You can enhance its functionality with plug-ins. And, last but not least, you can totally unleash WordPress\u2019 power with hacks. Some time ago, we wrote a post showing10 Killer WordPress Hacks.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/edynamo.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/320"}],"collection":[{"href":"http:\/\/edynamo.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/edynamo.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/edynamo.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/edynamo.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=320"}],"version-history":[{"count":16,"href":"http:\/\/edynamo.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/320\/revisions"}],"predecessor-version":[{"id":322,"href":"http:\/\/edynamo.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/320\/revisions\/322"}],"wp:attachment":[{"href":"http:\/\/edynamo.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edynamo.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=320"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edynamo.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}