<?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>Web Developers Corner</title>
	<atom:link href="http://www.webdevcorner.net/feed" rel="self" type="application/rss+xml" />
	<link>http://www.webdevcorner.net</link>
	<description>A site for developers and designers</description>
	<lastBuildDate>Fri, 13 Jan 2017 19:43:21 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.7.29</generator>
	<item>
		<title>Over 785.000 websites were down due to an system wide network issue with CloudFlare</title>
		<link>http://www.webdevcorner.net/articles/over-785-000-websites-were-down-due-to-an-system-wide-network-issue-with-cloudflare</link>
		<comments>http://www.webdevcorner.net/articles/over-785-000-websites-were-down-due-to-an-system-wide-network-issue-with-cloudflare#respond</comments>
		<pubDate>Sun, 03 Mar 2013 11:20:32 +0000</pubDate>
		<dc:creator><![CDATA[Fredrik Hugås]]></dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Featured]]></category>

		<guid isPermaLink="false">http://www.webdevcorner.net/?p=449</guid>
		<description><![CDATA[<p>Today (March 3rd 2013) I noticed my webpage was suddenly down, of course I thought the problem was on my server, especially since I just updated some things on it. I couldn&#8217;t find anything out of the order, and I checked some of the other sites I run on the server, they were ok. Then [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://www.webdevcorner.net/articles/over-785-000-websites-were-down-due-to-an-system-wide-network-issue-with-cloudflare">Over 785.000 websites were down due to an system wide network issue with CloudFlare</a> appeared first on <a rel="nofollow" href="http://www.webdevcorner.net">Web Developers Corner</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Today (March 3rd 2013) I noticed my webpage was suddenly down, of course I thought the problem was on my server, especially since I just updated some things on it.</p>
<p>I couldn&#8217;t find anything out of the order, and I checked some of the other sites I run on the server, they were ok.</p>
<p>Then I paid attention to the error chrome was giving, it said something about DNS error. so I went to cloudflare.com to see what was going on, but their page was down as well.</p>
<p>I headed over to their twitter and facebook to see if they had some information about this issue.</p>
<p><img class="aligncenter size-full wp-image-450" alt="Cloduflare down twitter status" src="http://www.webdevcorner.net/wp-content/uploads/2013/03/2013-03-03-11_19_01-CloudFlare-CloudFlare-on-Twitter.png" width="528" height="455" srcset="http://www.webdevcorner.net/wp-content/uploads/2013/03/2013-03-03-11_19_01-CloudFlare-CloudFlare-on-Twitter.png 528w, http://www.webdevcorner.net/wp-content/uploads/2013/03/2013-03-03-11_19_01-CloudFlare-CloudFlare-on-Twitter-300x258.png 300w" sizes="(max-width: 528px) 100vw, 528px" /></p>
<p>The problem affected both their proxy service as well as their DNS service and was a result of bad routing, and appeared around 11.00 CET and lasted for about 1 hour.</p>
<p>A simple search for #cloudflare on twitter yielded alot of frustrated peoples and customers pulling their hair out because of this &#8220;blackout&#8221;</p>
<p>The post <a rel="nofollow" href="http://www.webdevcorner.net/articles/over-785-000-websites-were-down-due-to-an-system-wide-network-issue-with-cloudflare">Over 785.000 websites were down due to an system wide network issue with CloudFlare</a> appeared first on <a rel="nofollow" href="http://www.webdevcorner.net">Web Developers Corner</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevcorner.net/articles/over-785-000-websites-were-down-due-to-an-system-wide-network-issue-with-cloudflare/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Make WordPress validate for HTML5 by getting rid of rel=&#8221;category tag&#8221;</title>
		<link>http://www.webdevcorner.net/articles/make-wordpress-validate-for-html5-by-getting-rid-of-relcategory-tag</link>
		<comments>http://www.webdevcorner.net/articles/make-wordpress-validate-for-html5-by-getting-rid-of-relcategory-tag#comments</comments>
		<pubDate>Wed, 23 Jan 2013 15:42:48 +0000</pubDate>
		<dc:creator><![CDATA[Fredrik Hugås]]></dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[category]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[rel]]></category>
		<category><![CDATA[tag]]></category>
		<category><![CDATA[validate]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.webdevcorner.net/?p=412</guid>
		<description><![CDATA[<p>Have you tried validating your WordPress site using the W3C validator thinking your site was up to par with today's standards? Only to see a long list of errors on your site? Don't worry, we all have been there, well most of us at least. And there is only one thing to do about the problems, fix them. If your site is using html5, then you probably have a lot of errors complaining about a bad value for your rel attributes (rel="category tag")</p>
<p>The post <a rel="nofollow" href="http://www.webdevcorner.net/articles/make-wordpress-validate-for-html5-by-getting-rid-of-relcategory-tag">Make WordPress validate for HTML5 by getting rid of rel=&#8221;category tag&#8221;</a> appeared first on <a rel="nofollow" href="http://www.webdevcorner.net">Web Developers Corner</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Have you tried validating your WordPress site using the W3C validator thinking your site was up to par with today&#8217;s standards? Only to see a long list of errors on your site?</p>
<p>Don&#8217;t worry, we all have been there, well most of us at least. And there is only one thing to do about the problems, fix them. If your site is using html5, then you probably have a lot of errors complaining about a bad value for your rel attributes (<em>rel=&#8221;category tag&#8221;</em>)</p>
<p>If this is the error you are searching for then you can relax because there is an easy solution for this problem.</p>
<ul style="margin: 0;">
<li style="margin: 0; vertical-align: baseline; color: #1f2126; line-height: 1; font-weight: normal; font-style: normal; font-size: 100%; font-family: Helvetica, Arial, Sans-Serif; border: 1px solid #EAEBEE; list-style: none; padding: 1em; padding-bottom: 2em; clear: both;"><img style="margin: 0; width: 1.2em; height: 1.2em; padding-bottom: .2em; vertical-align: middle;" title="Error" alt="Error" src="/media/error.png" /><em style="font-weight: normal; font-style: italic; font-size: 100%; font-family: Helvetica, Arial, Sans-Serif; color: #1f2126; line-height: 1; text-align: left;">Line 562, Column 288</em>: <span style="font-weight: bold; line-height: 130%;" data-mce-mark="1">Bad value category tag for attribute rel on element a: The string category is not a registered keyword or absolute URL. Whitespace in path component. Use %20 in place of spaces.</span><br />
<code style="display: block; font-family: 'Bitstream Vera Sans Mono', monospace; margin: 1em 0; color: #000; background-color: #eaebee; font-size: small;">…press" title="View all posts in WordPress" rel="category tag"<strong style="color: red; padding-left: .5ex; padding-right: .5ex; font-weight: bolder; border-bottom: thin dotted; cursor: help;" title="Position where error was detected.">&gt;</strong>WordPress&lt;/a&gt;&lt;/p&gt;</code></p>
<div style="margin: 0; border: 0; font-weight: normal; font-style: normal; font-family: Helvetica, Arial, Sans-Serif; vertical-align: baseline; background-color: white; color: #1f2126; line-height: 1; text-align: left; font-size: smaller; padding: 0; width: 100%;">
<dl>
<dt style="font-weight: normal;">Syntax of link type valid for &lt;a&gt; and &lt;area&gt;:</dt>
<dd style="margin: 0 0 0 34px;">A whitespace-separated list of link types listed as allowed on <code style="background-color: transparent;">&lt;a&gt;</code> and <code style="background-color: transparent;">&lt;area&gt;</code> in the <a style="color: #365d95;" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#linkTypes">HTML specification</a> or listed as an allowed on <code style="background-color: transparent;">&lt;a&gt;</code> and <code style="background-color: transparent;">&lt;area&gt;</code> on the <a style="color: #365d95;" href="http://microformats.org/wiki/existing-rel-values#HTML5_link_type_extensions">Microformats wiki</a> without duplicate keywords in the list. <strong>You can register link types on the <a style="color: #365d95; font-weight: normal;" href="http://microformats.org/wiki/existing-rel-values#HTML5_link_type_extensions">Microformats wiki</a> yourself.</strong></dd>
<dt style="font-weight: normal;">Syntax of absolute IRI:</dt>
<dd style="margin: 0 0 0 34px;">An absolute URL. For example: <code style="background-color: transparent;">http://example.org/hello</code>, but not <code style="background-color: transparent;">/hello</code>. Spaces should be escaped as <code style="background-color: transparent;">%20</code>.</dd>
</dl>
</div>
</li>
</ul>
<p>The problem is not within your theme but in fact inside the core of WordPress, more specifically the function <em>the_category() </em>And to fix this all you need to do is add a few lines of code to your themes <em>functions.php</em> file</p>
<pre class="prettyprint">add_filter('the_category', 'fix_cat');

function fix_cat($text) {
    return str_replace('rel="category tag"', '', $text);
}</pre>
<p>What we have done here is adding a filter to the <em>the_category</em> function. This filters the contents from the function through a function I have chose to call <i>fix_cat().</i> On the next lines we can see what the function does. I takes 1 argument <i>$text</i> and returns it after we have replaced all occurenses of <em>rel=&#8221;category</em> tag&#8221; with a blank string (&#8220;&#8221;)</p>
<p>The post <a rel="nofollow" href="http://www.webdevcorner.net/articles/make-wordpress-validate-for-html5-by-getting-rid-of-relcategory-tag">Make WordPress validate for HTML5 by getting rid of rel=&#8221;category tag&#8221;</a> appeared first on <a rel="nofollow" href="http://www.webdevcorner.net">Web Developers Corner</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevcorner.net/articles/make-wordpress-validate-for-html5-by-getting-rid-of-relcategory-tag/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Need for speed: mod_pagespeed an Apache module for faster websites</title>
		<link>http://www.webdevcorner.net/articles/need-for-speed-mod_pagespeed-an-apache-module-for-faster-websites</link>
		<comments>http://www.webdevcorner.net/articles/need-for-speed-mod_pagespeed-an-apache-module-for-faster-websites#respond</comments>
		<pubDate>Sun, 11 Nov 2012 04:07:26 +0000</pubDate>
		<dc:creator><![CDATA[Fredrik Hugås]]></dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mod_pagespeed]]></category>
		<category><![CDATA[page speed]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.webdevcorner.net/?p=383</guid>
		<description><![CDATA[<p>mod_pagespeed is an open-source Apache module that make Apache rewrite and resize your assets (CSS, JavaScript, images) without requiring that you modify your existing content or workflow. mod_pagespeed is built on PageSpeed Optimization Libraries, deployed across 100,000+ web-sites, and provided by popular hosting and CDN providers such as DreamHost, GoDaddy, EdgeCast, and others. A good example [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://www.webdevcorner.net/articles/need-for-speed-mod_pagespeed-an-apache-module-for-faster-websites">Need for speed: mod_pagespeed an Apache module for faster websites</a> appeared first on <a rel="nofollow" href="http://www.webdevcorner.net">Web Developers Corner</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p><strong>mod_pagespeed is an open-source Apache module that make Apache rewrite and resize your assets (CSS, JavaScript, images) without requiring that you modify your existing content or workflow.</strong></p>
<p>mod_pagespeed is built on <a href="https://developers.google.com/speed/pagespeed/psol" rel="nofollow">PageSpeed Optimization Libraries</a>, deployed across 100,000+ web-sites, and provided by popular hosting and CDN providers such as DreamHost, GoDaddy, EdgeCast, and others.</p>
<div id="attachment_388" style="width: 632px" class="wp-caption aligncenter"><img class="size-large wp-image-388" title="mod_pagespeed integration into Apache" src="http://www.webdevcorner.net/wp-content/uploads/2012/11/2012-11-10_18-04-20-1024x576.png" alt="This illustrates how mod_pagespeed works using filters for input and output from the apache kernel" width="622" height="349" srcset="http://www.webdevcorner.net/wp-content/uploads/2012/11/2012-11-10_18-04-20-1024x576.png 1024w, http://www.webdevcorner.net/wp-content/uploads/2012/11/2012-11-10_18-04-20-300x168.png 300w, http://www.webdevcorner.net/wp-content/uploads/2012/11/2012-11-10_18-04-20-622x350.png 622w" sizes="(max-width: 622px) 100vw, 622px" /><p class="wp-caption-text">mod_pagespeed works is using input/output filters that attaches them selves to the Apache kernel, these filters filters and rewrites data from http requests and response. It looks at the content and caches optimized versions of your assets (Images, CSS and JavaScript)</p></div>
<p>A good example of this is when someone use a large image for a thumbnail and resize it in the html code instead of making a smaller copy of the image. This makes the visitors download a much lager image than they need to, which takes up bandwidth and adds to the loading time of the page</p>
<p><img class="aligncenter size-full wp-image-400" title="Using large images for thumbnails is not advised" src="http://www.webdevcorner.net/wp-content/uploads/2012/11/image-scale-down1.jpg" alt="Using large images for thumbnails is not advised" width="615" height="569" srcset="http://www.webdevcorner.net/wp-content/uploads/2012/11/image-scale-down1.jpg 615w, http://www.webdevcorner.net/wp-content/uploads/2012/11/image-scale-down1-300x277.jpg 300w" sizes="(max-width: 615px) 100vw, 615px" /></p>
<p>One solution would be to make smaller versions of the image, either using php or another server side language when the image is uploaded or manually, which is a painstaking process. But with mod_pagespeed there is no need for either of this, since it resizes images on demand.</p>
<h3>So how does this work?</h3>
<p>The first time a page is requested apache sends the original page, the content goes through the output filter which parse the html code, when the parser see a <em>img</em> tag it checks if this image with this dimensions are in the cache, if not, the original image is sent, and the image is added to the queue for later processing.</p>
<h3>Later processing?</h3>
<p>This is a process that runs in the background so it wont affect the page speed. This process creates an optimized scaled down version of the image using the height and width from the html code, and saves it to the cache.</p>
<p>Next time this page is requested, the parser finds the image in the cache and rewrites the <em>img</em> tag on the fly, making the browsers download the much smaller optimized version of the image.</p>
<p>Notice what happened to the filename there, the output filter appended a string containing the tag pagespeed and a hash, when the browser requests an asset with the tag pagespeed the input filter will know this is a cached asset and will use the cached resource instead of the original.</p>
<h2>Is that all it does?</h2>
<p>No-no, it also compresses the images by lowering the quality of them to an acceptable value if set, and optimizes images by removing meta-data.</p>
<p>mod_pagespeed also works with css and javascript files, removing whitespace and comments, this allows you to have readable files with comments if you like, saving you the trouble of minification.</p>
<p>It also concatenate serveral files into one file. This is great for WordPress blogs with alot of plugins, since they tend to have a lot of extra javascript and css includes.</p>
<p>There are 40+ available optimizations filters, which include:</p>
<ul>
<li>Image optimization, compression, and resizing</li>
<li>CSS &amp; JavaScript concatenation, minification, and inlining</li>
<li>Cache extension, domain sharding, and domain rewriting</li>
<li>Deferred loading of JavaScript and image resources</li>
<li>and <a href="https://developers.google.com/speed/docs/mod_pagespeed/config_filters" rel="nofollow">many others</a>&#8230;</li>
</ul>
<p>The post <a rel="nofollow" href="http://www.webdevcorner.net/articles/need-for-speed-mod_pagespeed-an-apache-module-for-faster-websites">Need for speed: mod_pagespeed an Apache module for faster websites</a> appeared first on <a rel="nofollow" href="http://www.webdevcorner.net">Web Developers Corner</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevcorner.net/articles/need-for-speed-mod_pagespeed-an-apache-module-for-faster-websites/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shorthand if/else for PHP</title>
		<link>http://www.webdevcorner.net/articles/shorthand-ifelse-for-php</link>
		<comments>http://www.webdevcorner.net/articles/shorthand-ifelse-for-php#comments</comments>
		<pubDate>Fri, 12 Oct 2012 00:09:48 +0000</pubDate>
		<dc:creator><![CDATA[Fredrik Hugås]]></dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[elseif]]></category>
		<category><![CDATA[if/else]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[shorthand]]></category>
		<category><![CDATA[ternary]]></category>

		<guid isPermaLink="false">http://www.webdevcorner.net/?p=345</guid>
		<description><![CDATA[<p>There is a special if/else functionality available that not many programmers know how to utilize that I now want to share with you. This function is called a Ternary operation. The ternary operation takes 3 arguments, The first which is the conditional expression, the second is what get returned if the conditional expression is true, the third if it returns false.</p>
<p>The post <a rel="nofollow" href="http://www.webdevcorner.net/articles/shorthand-ifelse-for-php">Shorthand if/else for PHP</a> appeared first on <a rel="nofollow" href="http://www.webdevcorner.net">Web Developers Corner</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>There is a special if/else functionality available that not many programmers know how to utilize that I now want to share with you. This function is called a <a title="Ternary operation" href="http://en.wikipedia.org/wiki/Ternary_operation" target="_blank">Ternary operation</a>. The ternary operation takes 3 arguments, The first which is the conditional expression, the second is what get returned if the conditional expression is true, the third if it returns false.</p>
<p>First let&#8217;s see a standard if/else, this example should look familiar.</p>
<pre class="prettyprint">if($age &gt; 50) {
    echo 'You are old!';
} else {
    echo 'You are young!';
}</pre>
<p>Now let&#8217;s try that with the shorthand version of if/else</p>
<pre class="prettyprint">echo ($age &gt; 50 ? 'You are old!' : 'You are young!');</pre>
<p style="text-align: center;">[adsense-banner]</p>
<p>What was that you say? That is about what I said the first time I encountered this type of conditional statement. If you look closer at this example you can see the same conditional expression from the first example followed by a question mark. Then we have 2 strings divided by a colon. The first of the 2 strings is returned if the condition is true, and the second is returned if the condition is false.</p>
<p>If you are new to programming this kind of operations may be hard to follow,  at least to remember when writing your own code. But as soon as you get used to it, you will end up with much cleaner code provided that you don&#8217;t pull any crazy stunts using this method.</p>
<h3>What about elseif?</h3>
<p>Yes it&#8217;s possible to do elseif statements using this method as well if your&#8217;e willing to sacrifice some of the readability. To do elseif you need to wrap a ternary operation as the <em>false</em> part of you main if/else statement.</p>
<pre class="prettyprint">echo ($age &gt; 50 ? 'You are old!' : ($age &lt; 20 ? 'You are too young!' : 'You are young!'));</pre>
<p>And if you really want to get down and dirty you could replace the true part with another shorthand version although this is not something I would recommend doing.</p>
<pre class="prettyprint">echo ($age &gt; 50 ? ($age &gt; 75 'You are too old!' : 'You are old!') : ($age &lt; 20 ? 'You are too young!' : 'You are young!'));</pre>
<p>The post <a rel="nofollow" href="http://www.webdevcorner.net/articles/shorthand-ifelse-for-php">Shorthand if/else for PHP</a> appeared first on <a rel="nofollow" href="http://www.webdevcorner.net">Web Developers Corner</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevcorner.net/articles/shorthand-ifelse-for-php/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to send mail with PHP</title>
		<link>http://www.webdevcorner.net/articles/how-to-send-mail-with-php</link>
		<comments>http://www.webdevcorner.net/articles/how-to-send-mail-with-php#respond</comments>
		<pubDate>Tue, 11 Sep 2012 01:43:34 +0000</pubDate>
		<dc:creator><![CDATA[Fredrik Hugås]]></dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.webdevcorner.net/?p=110</guid>
		<description><![CDATA[<p>Sometimes you want to send mail from your php code, maybe you want to send a mail to yourself on an event or send a message to your users or subscribers, don&#8217;t fear this is not a hard task to accomplish, and as usual in programming, there is many paths to the same goal, some are not as safe [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://www.webdevcorner.net/articles/how-to-send-mail-with-php">How to send mail with PHP</a> appeared first on <a rel="nofollow" href="http://www.webdevcorner.net">Web Developers Corner</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Sometimes you want to send mail from your php code, maybe you want to send a mail to yourself on an event or send a message to your users or subscribers, don&#8217;t fear this is not a hard task to accomplish, and as usual in programming, there is many paths to the same goal, some are not as safe and stable, while others may require a little more effort. It all depends on your needs.</p>
<p style="text-align: center;">[adsense-banner]</p>
<h2>Option 1: PHP&#8217;s built-in mail function (Not recommended)</h2>
<p>Sending mail with PHP is quite easy if the server is set up for it. The server needs to have SendMail installed and configured correctly in php.ini. There are also some people reporting that mail doesn&#8217;t reach the destination, even though the mail was sent without an error message and some providers does not allow mails sent by php mail() to prevent spam.</p>
<p>Also if you want custom headers and attachments or special encodings you have a lot of job in front of you. I had this issue myself  a while ago when a clients script was sending a PDF file as an attachment using the php mail() function. It worked just fine in testing, I was testing with Gmail, but some recipients got the PDF code garbeled inside the body of the mail.</p>
<p>If this is fine with you, and you are only going to send a mail to yourself and want something simple then you can go ahead and try it out:</p>
<pre class="prettyprint">mail('recipient@email.com', 'PHP test mail', 'This is a test mail');</pre>
<p>If the mail appear in your inbox, the server is configured correctly and you can use it for simple mails, but bear in mind that this is not stable.</p>
<h2>Option 2: Use a dedicated mail class</h2>
<p>If you want something more stable than the php mail function you should try a mail class that gives you a lot of functionality and options, and handles the hard work with attachments and headers for you.</p>
<p>There is a open source project called <a title="PHPMailer email Transport class" href="http://sourceforge.net/projects/phpmailer/" target="_blank">PHPMailer</a> available that handles file attachments, SMTP servers, CCs, BCCs, HTML messages, word wrap, and more. This class gives you the options to send emails via sendmail, PHP mail(), QMail, or using your own SMTP server.</p>
<p>All you need to do is download the class files and include it to your project to get going.</p>
<p><strong>A simple example showing how to send emails using your own SMTP server.</strong></p>
<pre class="prettyprint">include 'class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth=true;
$mail->Host = 'smtp.yourmailserver.com';
$mail->Username="your@email.com";
$mail->Password="your_password";
$mail->SetFrom('your@email.com', 'Your name');
$mail->AddReplyTo('your@email.com', 'Your name');
$mail->Subject = 'PHP test mail';
$mail->ContentType="text/plain";
$mail->Body('This is a test mail sent from php'); 
$mail->AddAddress('recipient@email.com');

if(!$mail->Send()) {
    echo('Mail not sent: '.$mail->ErrorInfo;
} else {
    echo('Mail sent successfully!');
}</pre>
<p>If this example does not suit your needs, you can find more advanced examples over at the <a title="WorxWare PHPMailer examples" href="http://phpmailer.worxware.com/index.php?pg=examples" target="_blank">developers website</a> using other choices to send mail, and Gmail SMTP.</p>
<p style="text-align: center;">[adsense-banner]</p>
<p>The post <a rel="nofollow" href="http://www.webdevcorner.net/articles/how-to-send-mail-with-php">How to send mail with PHP</a> appeared first on <a rel="nofollow" href="http://www.webdevcorner.net">Web Developers Corner</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevcorner.net/articles/how-to-send-mail-with-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress RSS &#8211; Display data from external sources</title>
		<link>http://www.webdevcorner.net/articles/wordpress-rss-display-data-from-external-pages</link>
		<comments>http://www.webdevcorner.net/articles/wordpress-rss-display-data-from-external-pages#respond</comments>
		<pubDate>Fri, 17 Aug 2012 01:13:42 +0000</pubDate>
		<dc:creator><![CDATA[Fredrik Hugås]]></dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[feed]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[rss]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.webdevcorner.net/?p=287</guid>
		<description><![CDATA[<p>WordPress has built-in functionality for parsing RSS files from other sources, this means that you can fetch the latest blog posts or articles from another site and display them on your own site. We will use this to fetch a feed from an external site and display it on our site.</p>
<p>The post <a rel="nofollow" href="http://www.webdevcorner.net/articles/wordpress-rss-display-data-from-external-pages">WordPress RSS &#8211; Display data from external sources</a> appeared first on <a rel="nofollow" href="http://www.webdevcorner.net">Web Developers Corner</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>RSS is often used to publish frequently updated works, such as blog entries, news headlines etc. in a standardized format. An RSS document includes full or summarized text, plus metadata such as publishing dates and authorship. A standardized XML file format allows the information to be published once and viewed by many different programs. They benefit readers who want to subscribe to timely updates from favorite websites or to aggregate feeds from many sites into one place.</p>
<p style="text-align: center;">[adsense-banner]</p>
<p>WordPress has built-in functionality for parsing RSS files from other sources, this means that you can fetch the latest blog posts or articles from another site and display them on your own site. The RSS parser shipped with WordPress let&#8217;s you define an RSS feed to read from and gives you an array where each entry describes a single post or article.</p>
<pre class="prettyprint linenums">include_once(ABSPATH.WPINC.'/feed.php');
$parser = fetch_feed('http://www.webdevcorner.net/feed');</pre>
<p>This code includes the file we need for the feed parser, fetches the feed from the specified url, make sure to specify a valid RSS feed, the resulting feed is returned as a standard SimplePie object. Now lets do something with this object.</p>
<pre class="prettyprint linenums:3">if (!is_wp_error( $parser ) ) :
    // Fetch only the 5 last items from this feed
    $maxitems = $parser->get_item_quantity(5); 

    // Create an array holding the items
    $items = $parser->get_items(0, $maxitems); 
endif;</pre>
<p>Here you can see we fetch the 5 last items from our RSS feed, note that we put this inside a if statement that checks if our parser object has an error. Then we create an array ($items) to hold our items.</p>
<pre class="prettyprint linenums:11"><ul>
    <?php if ($maxitems == 0) echo '<li>The feed is empty.</li>';
    else
        // Loop through each feed item and display each item as a hyperlink.
    foreach ( $items as $item ) : ?>;
        <li>
            <a href="<?php echo esc_url( $item->get_permalink() ); ?>" 
            title="<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>">
            <?php echo esc_html( $item->get_title() ); ?></a>
        </li>
    <?php endforeach; ?>;
</ul>;</pre>
<p>Here we looped through our items and output a simple list of links with the titles from our RSS feed. You don&#8217;t have to worry about this code pulling the RSS feed on every request, because by by default the function <em>fetch_feed</em> caches the results for 12 hours. This may be way too long for some people. But don&#8217;t worry, <a title="Change cache interval for fetch_feed" href="http://www.webdevcorner.net/articles/wordpress-rss-display-data-from-external-pages/2">on the next page you will learn how to change this interval</a> so hang tight.</p>
<p>The post <a rel="nofollow" href="http://www.webdevcorner.net/articles/wordpress-rss-display-data-from-external-pages">WordPress RSS &#8211; Display data from external sources</a> appeared first on <a rel="nofollow" href="http://www.webdevcorner.net">Web Developers Corner</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevcorner.net/articles/wordpress-rss-display-data-from-external-pages/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash support for Android is history</title>
		<link>http://www.webdevcorner.net/articles/flash-support-for-android-is-history</link>
		<comments>http://www.webdevcorner.net/articles/flash-support-for-android-is-history#respond</comments>
		<pubDate>Wed, 15 Aug 2012 14:57:12 +0000</pubDate>
		<dc:creator><![CDATA[Fredrik Hugås]]></dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[google play]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://www.webdevcorner.net/?p=293</guid>
		<description><![CDATA[<p>Today Google Play stopped providing their users with the ability to download and install Flash on their Android devices. This means Android now longer will support Flash, the number one advantage they had over iOS. This will also give HTML5 a boost in popularity.</p>
<p>The post <a rel="nofollow" href="http://www.webdevcorner.net/articles/flash-support-for-android-is-history">Flash support for Android is history</a> appeared first on <a rel="nofollow" href="http://www.webdevcorner.net">Web Developers Corner</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Adobe have been under heavy preassure from HTML5 lately, now they (finally) lost the war. I say finally because I have never liked the non-proprietary idea of Flash.</p>
<p><img class="aligncenter size-full wp-image-302" title="Today Google Play dropped the support for Flash player on Android devices" src="http://www.webdevcorner.net/wp-content/uploads/2012/08/android-flash-no-html5-yes.jpg" alt="Today Google Play dropped the support for Flash player on Android devices" width="520" height="257" srcset="http://www.webdevcorner.net/wp-content/uploads/2012/08/android-flash-no-html5-yes.jpg 520w, http://www.webdevcorner.net/wp-content/uploads/2012/08/android-flash-no-html5-yes-300x148.jpg 300w" sizes="(max-width: 520px) 100vw, 520px" /></p>
<p>&nbsp;</p>
<h2>The complete internet experience</h2>
<p style="text-align: justify;">In 2007 Adobe were active marketing Flash for mobile, the only alternative to enjoy the complete internet experience on a mobile device according to Adobe.</p>
<p style="text-align: justify;">When Flash finally got available on Android the industry was getting ready to move on to HTML5 . a way more flexible, safe, and not least non-proprietary solution. Flash support is also the number one advantage Android have had over iOS, but this has now come to an end.</p>
<p style="text-align: center;">[adsense-banner]</p>
<h2>Stop for android</h2>
<p>Today is the beginning of the end for the Flash standard which has provided Adobe a solid foothold, not only as the developer of flash, but also creative suites for designing flash content.</p>
<p style="text-align: justify;">Adobe has benefited from their strong position in the market for a very long time now, but surely has to adapt to more and more HTML5 competition in the future.</p>
<p style="text-align: justify;">Today Google Play stopped providing Flash for their user, now it&#8217;s not possible to download and install Flash from their market service. This is good news for web developers that has adopted to HTML5.</p>
<p>The post <a rel="nofollow" href="http://www.webdevcorner.net/articles/flash-support-for-android-is-history">Flash support for Android is history</a> appeared first on <a rel="nofollow" href="http://www.webdevcorner.net">Web Developers Corner</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevcorner.net/articles/flash-support-for-android-is-history/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimizing your page speed for visitors and SEO</title>
		<link>http://www.webdevcorner.net/articles/optimizing-your-page-speed-for-visitors-and-seo</link>
		<comments>http://www.webdevcorner.net/articles/optimizing-your-page-speed-for-visitors-and-seo#respond</comments>
		<pubDate>Wed, 08 Aug 2012 06:11:07 +0000</pubDate>
		<dc:creator><![CDATA[Fredrik Hugås]]></dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[page speed]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[seo]]></category>

		<guid isPermaLink="false">http://www.webdevcorner.net/?p=254</guid>
		<description><![CDATA[<p>Ancient history Nowadays many web developers around the world underestimate the impact page size has on their sites performance. Back in the days before broadband was considered a standard, people was sitting on slow internet connection with their modems. Back then web developers had to make their pages small enough for those modem users, the [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://www.webdevcorner.net/articles/optimizing-your-page-speed-for-visitors-and-seo">Optimizing your page speed for visitors and SEO</a> appeared first on <a rel="nofollow" href="http://www.webdevcorner.net">Web Developers Corner</a>.</p>
]]></description>
				<content:encoded><![CDATA[<h3>Ancient history<br />
<img class="alignright  wp-image-255" title="A good old 14.4k modem from 1995 - This was the common way to access internet for many years" src="http://www.webdevcorner.net/wp-content/uploads/2012/08/s_p_12377_1__59275_zoom-300x225.jpg" alt="A modem with slow internet connection" width="180" height="135" srcset="http://www.webdevcorner.net/wp-content/uploads/2012/08/s_p_12377_1__59275_zoom-300x225.jpg 300w, http://www.webdevcorner.net/wp-content/uploads/2012/08/s_p_12377_1__59275_zoom.jpg 600w" sizes="(max-width: 180px) 100vw, 180px" /></h3>
<p style="text-align: justify;">Nowadays many web developers around the world underestimate the impact page size has on their sites performance. Back in the days before broadband was considered a standard, people was sitting on slow internet connection with their modems. Back then web developers had to make their pages small enough for those modem users, the page structure was not that complicated, the images and javascripts were kept to a minimum or else people had to wait for ever to load a single webpage.</p>
<h3>New times</h3>
<p style="text-align: justify;"><img class="wp-image-262 alignright" title="Now most visitors are sitting on fast internet connections" src="http://www.webdevcorner.net/wp-content/uploads/2012/08/images.jpg" alt="Now most visitors are sitting on fast internet connections" width="186" height="132" />Today the story is different, most visitors are sitting on lightning fast internet connections, so the page speed doesn&#8217;t have such an impact on the visitors anymore. This has given web developers the freedom to utilize much more images, css and javascript in their designs which has resulted in some pretty amazing designs. The focus has been shifted from optimizing the code and minifying images to perfecting the design inside photoshop or fireworks. This shift of focus has made designers sloppy, they doesn&#8217;t have the optimizing mindset in the back of their head like the old school designers had to have.</p>
<p>Not only have the load time of the pages improved (a lot), but peoples expectations has gotten higher, if a page takes too long to load people are getting annoyed and bored, and the threshold for pressing the back button and go to the next page in the search results are considerably lower now than before. Studies have shown that most people lose loyalty and interest for your page if it loads slow, and are not likely to come back.</p>
<p style="text-align: center;">[adsense-banner]</p>
<h2>Search Engine Optimization</h2>
<p>The visitors are not the only ones that get bored with slow pages, now Google also takes page load times into account when calculating page ranks. And since the goal in SEO is to get to the top of the search results in search engines this is a area we as web developers can&#8217;t ignore, although pages speed doesn&#8217;t have a huge impact on page ranks as other factors of SEO has it&#8217;s worth taking a look at.</p>
<h2>Minify Page size</h2>
<p>This step is pretty straight forward, go through your HTML or template files, see if there is some way you can simplify your design, remove unnecessary elements, maybe you can do somethings a different way, try utilize CSS to get the same results. Make sure all your CSS is in external files instead of inline mixed with your HTML. Also make sure you <a title="Why you should reset the css style sheet" href="http://www.webdevcorner.net/design/why-you-should-reset-the-css-style-sheet">properly reset your CSS</a> styles and remove unnecessary styles and that CSS shorthand is used.</p>
<h2>Remove Whitespace</h2>
<p>Unnecessary whitespace does not add any value to your page other than making it larger in size. The web browser strips it away before rendering the page anyways, so you can lose some weight by removing them for good. How far you want to take this is up to you, by removing the whitespace you also reduce the readability, so if you plan on editing the code later on I would recommend you to only remove as much as you can while still being able to read it, take away double line breaks, If you plan on keeping indentations make sure they are done with tabs instead of spaces (1 tab usually converts to 4 spaces &#8211; This would cut the &#8220;indentation cost&#8221; by 75%) You have to consider how much you can get out of this, and if it&#8217;s worth it.</p>
<p style="text-align: center;">[adsense-banner]</p>
<h2>Optimize images</h2>
<p>Make sure your images aren&#8217;t stored in larger dimensions than you are presenting them to the visitors, it&#8217;s a waste to have the visitor download a 1024&#215;768 image if all they see is a thumbnail or sized down version of the image. When you are sure your images aren&#8217;t unnecessary large, make sure they are compressed and optimized to decrease the file size. You can use an online tool like <a title="Optimize images for web" href="http://www.smushit.com/ysmush.it/" target="_blank">Smush.it</a> to remove unnecessary data from the images.</p>
<h2>Parallel loading</h2>
<p>Browsers has a limitation on how many concurrent connections they can open to a single domain, this means it will queue the downloading of resources from your server, but if you place your javascript and images on multiple domains e.g. <em>www.domain.com</em> and <em>images.domain.com</em> (it can still be on the same server) the browser won&#8217;t have to wait for 1 resource to finish before starting on the next one. You should also considering a content delivery network for storing your resources on. Note that the client will have to do a DNS look-up for each domain you present it with, so it&#8217;s not recommended that you use more than a few since it takes some time to look-up the domain.</p>
<h2>Caching resources</h2>
<p>Check that all your static resources are being cached properly, this can be done by placing a <em>.htaccess</em> file inside the folder for your resources that will add and Expires header to all files inside that folder.</p>
<pre class="prettyprint"><IfModule mod_expires.c>
  ExpiresActive on
  ExpiresDefault "access plus 1 year"
</IfModule></pre>
<h2>Placement of JavaScript</h2>
<p>Place JavaScript that is not precarious for the loading of the page at the end of the document. This is because the sequential processing of JavaScript holds up the rendering of the page. You should also consider compressing the JavaScript files if you have lots of JavaScript.</p>
<h2>Compressing files</h2>
<p>There are several ways to compress our files before sending them to the client, if you are running apache there is mod_deflate which will compress the files you have specified in the <em>.htaccess</em> file like this:</p>
<pre class="prettyprint">AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript</pre>
<p>If you are using PHP you got an even more powerfull compression at your disposal, namely gzip. To enable gzip compression of your output you need to enable output buffering at the beginning of your php files and specify that it will compress using gzip before sending it to the client. Be sure to check if the client accepts gzip, or else it will get garbled data. <img src="https://s.w.org/images/core/emoji/2.2.1/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<pre class="prettyprint">if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
    ob_start("ob_gzhandler");
else
    ob_start();</pre>
<p>The post <a rel="nofollow" href="http://www.webdevcorner.net/articles/optimizing-your-page-speed-for-visitors-and-seo">Optimizing your page speed for visitors and SEO</a> appeared first on <a rel="nofollow" href="http://www.webdevcorner.net">Web Developers Corner</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevcorner.net/articles/optimizing-your-page-speed-for-visitors-and-seo/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Twitter is down: Are we under attack?!</title>
		<link>http://www.webdevcorner.net/off-topic/twitter-is-down-are-we-under-attack</link>
		<comments>http://www.webdevcorner.net/off-topic/twitter-is-down-are-we-under-attack#respond</comments>
		<pubDate>Thu, 26 Jul 2012 18:46:38 +0000</pubDate>
		<dc:creator><![CDATA[Fredrik Hugås]]></dc:creator>
				<category><![CDATA[Off Topic]]></category>
		<category><![CDATA[down]]></category>
		<category><![CDATA[downtime]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[WhenTwitterWasDown]]></category>

		<guid isPermaLink="false">http://www.webdevcorner.net/?p=247</guid>
		<description><![CDATA[<p>The first major thing an invading country should do is to take down twitter to disrupt communication and spread panic amongst the population. This is common knowledge. Today I tried logging in to twitter, but I could not connect to the server, all other webpages worked as a charm, so I was sure this only [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://www.webdevcorner.net/off-topic/twitter-is-down-are-we-under-attack">Twitter is down: Are we under attack?!</a> appeared first on <a rel="nofollow" href="http://www.webdevcorner.net">Web Developers Corner</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>The first major thing an invading country should do is to take down twitter to disrupt communication and spread panic amongst the population. This is common knowledge.</p>
<p><img class="size-full wp-image-248 aligncenter" title="Twitter was down" src="http://www.webdevcorner.net/wp-content/uploads/2012/07/twitter-dead.png" alt="Today twitter went down, poor birdie" width="433" height="305" srcset="http://www.webdevcorner.net/wp-content/uploads/2012/07/twitter-dead.png 433w, http://www.webdevcorner.net/wp-content/uploads/2012/07/twitter-dead-300x211.png 300w" sizes="(max-width: 433px) 100vw, 433px" /></p>
<p>Today I tried logging in to twitter, but I could not connect to the server, all other webpages worked as a charm, so I was sure this only affected Twitter, are we under attack?! The logical answer would have been yes, but no there was no foreign planes in the sky, no explosions or enemies in sight. No signs of an attack at all. So we were safe.</p>
<p>According to their Status page they had some problem and their engineers were working to resolve the issue.</p>
<p>Phew! No invasion, we are safe.. ..for now..</p>
<p style="text-align: center;">[adsense-banner]</p>
<p>Twitter is now back online, we survived the first attack <img src="https://s.w.org/images/core/emoji/2.2.1/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>The post <a rel="nofollow" href="http://www.webdevcorner.net/off-topic/twitter-is-down-are-we-under-attack">Twitter is down: Are we under attack?!</a> appeared first on <a rel="nofollow" href="http://www.webdevcorner.net">Web Developers Corner</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevcorner.net/off-topic/twitter-is-down-are-we-under-attack/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Shortcodes</title>
		<link>http://www.webdevcorner.net/articles/wordpress-shortcodes</link>
		<comments>http://www.webdevcorner.net/articles/wordpress-shortcodes#respond</comments>
		<pubDate>Thu, 26 Jul 2012 15:36:47 +0000</pubDate>
		<dc:creator><![CDATA[Fredrik Hugås]]></dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[shortcode]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress post]]></category>

		<guid isPermaLink="false">http://www.webdevcorner.net/?p=223</guid>
		<description><![CDATA[<p>WordPress has a functionality called shortcodes which gives you the ability to insert generated elements into your posts just by typing in a shortcode in the text. All you need to do to make this work is to define a function in your theme’s functions.php file, and hook this funcion to a shortcode using WordPress API for shorcodes.</p>
<p>The post <a rel="nofollow" href="http://www.webdevcorner.net/articles/wordpress-shortcodes">WordPress Shortcodes</a> appeared first on <a rel="nofollow" href="http://www.webdevcorner.net">Web Developers Corner</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>WordPress has a functionality called shortcodes which gives you the ability to insert generated elements into your posts just by typing in a shortcode in the text. All you need to do to make this work is to define a function in your theme&#8217;s <em>functions.php</em> file, and hook this funcion to a shortcode using <a title="WordPress Shortcode API" href="http://codex.wordpress.org/Shortcode_API" target="_blank">WordPress API for shorcodes</a>. A shortcode is a word enclosed with <strong>[</strong> and <strong>]</strong> like</p>
<pre class="prettyprint">[this]</pre>
<p>What this means is that you can write a function in PHP, this could be anything you like, as long as it return some data. The data returned will replace the shortcode before the page is sent to the visitor. A popular use for this is Google AdSense, this would allow you to insert ads into your post by entering the code you defined for adsense. Now you can easily place ads where ever you want in your posts.</p>
<h2>First let&#8217;s try something simple</h2>
<p>First let&#8217;s create a simple function that returns the word <em>bar</em>. Open the file functions.php which is located in your theme&#8217;s directory.</p>
<pre class="prettyprint">function sc_foo() {
    return 'bar';
}</pre>
<p>Now whenever we call this function it will return a string with the word <em>bar</em>. it&#8217;s pretty straight forward.</p>
<p style="text-align: center;">[adsense-banner]</p>
<p>Now that we have our function in place let&#8217;s associate this function whit a shortcode. Place this line of code just below the function we just made. This code tells WordPress that whenever the word foo comes up in the form of a shortcode it should replace it with the data returned from the function sc_foo.</p>
<pre class="prettyprint">add_shortcode('foo', 'sc_foo');</pre>
<p>Now that we have this in place, let&#8217;s try it out shall we? Create a new post and type this inside the content text field:</p>
<pre> I did it! Now raise the [foo]...</pre>
<p>Now you can preview the post to see what it looks like. Now it should say <em>I did it! Now raise the bar&#8230;</em> If it does, it works great. If it did not work, make sure your installation of WordPress is up to date. <em>(Shortcodes has been available in WordPress since version 2.5.1)</em></p>
<h2>Let&#8217;s raise the bar</h2>
<p>The previous example was pretty straight forward, a simple function called from a simple shortcode. We could make the function more complex to return something more useful than bar, the sky is the limit for what we can make of this, if you want you can make shortcodes to display a gallery of images, calculate something, display a graph, or just a simple advertisement.</p>
<p>But there is much more to this API than displaying the output of simple functions, you can also pass arguments to the functions, and make the function wrap elements around some content text by using opening and closing tags.</p>
<h3>How to handle arguments</h3>
<p>You can set attributes inside the shortcode like this:</p>
<pre class="prettyprint">[banana color="yellow"]</pre>
<p>The attribute color now has the value of &#8220;yellow&#8221; and this will be sent as an argument to the function through the associative array $atts. Let&#8217;s see how we can access this atribute in our function.</p>
<pre class="prettyprint">function sc_banana($atts) {
    return "The banana is {$atts['color']}";
}
add_shortcode('banana', 'sc_banana');</pre>
<p>This would return <em>The banana is yellow</em>, which they usually are if they have not been lying on the kitchen counter for weeks. So why should we have to define the color of the banana if it&#8217;s yellow, can&#8217;t we set the default color to yellow and define the color if it&#8217;s not yellow? Sure.</p>
<pre class="prettyprint">function sc_banana($atts) {
    extract( shortcode_atts( array(
        'color' => 'yellow'
	), $atts ) );
    return "The banana is {$color}";
}</pre>
<p style="text-align: center;">[adsense-banner]</p>
<p>Now we have defined the default color to be yellow, if it&#8217;s set in the attributes then it will be overwritten with another color, if the attribute is left out it will still be yellow. The extract function will extract the attribute name from the array and set it to a variable</p>
<pre>[banana] -> The banana is yellow
[banana color="brown"] -> The banana is brown</pre>
<h3></h3>
<h3>Wrapping around some content text</h3>
<p>Now let&#8217;s write a function that wrap some text into a box for us, let&#8217;s call it something sketchy as <em>coolbox</em>, notice that we now will add the argument <em>$content</em> to our function.</p>
<pre class="prettyprint">function sc_coolbox($atts, $content) {
    extract( shortcode_atts( array(
        'class' => 'coolbox',
        'float' => 'left'
        ), $atts ) );
    return '<div class="'.$class.'" style="float:'.$float.';">'.$content.'</div>';
}
add_shortcode('coolbox', 'sc_coolbox');</pre>
<p>This function will wrap the text into a div with the default class of <em>coolbox</em></p>
<pre>[coolbox]This text will be wrapped into a div with the class coolbox,
the box will have a default floating of left[/coolbox]</pre>
<p>We can also give our box a custom class, or float it left and right.</p>
<pre>[coolbox class="coolbox-blue" float="right"]This text will be wrapped
into a blue div with right floating applied to it[/coolbox]</pre>
<p><strong>Note:</strong> If you change theme you would have to update your functions.php file in your new theme folder with this code.</p>
<p>The post <a rel="nofollow" href="http://www.webdevcorner.net/articles/wordpress-shortcodes">WordPress Shortcodes</a> appeared first on <a rel="nofollow" href="http://www.webdevcorner.net">Web Developers Corner</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.webdevcorner.net/articles/wordpress-shortcodes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
