<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>GrantPalin.com</title>
	
	<link>http://grantpalin.com</link>
	<description>Code, photos, books, and anything else</description>
	<lastBuildDate>Thu, 16 May 2013 23:23:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/grantpalin" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="grantpalin" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Extend WordPress – Contact Forms with Contact Form 7</title>
		<link>http://grantpalin.com/2013/05/15/extending-wordpress-contact-forms-with-contact-form-7/</link>
		<comments>http://grantpalin.com/2013/05/15/extending-wordpress-contact-forms-with-contact-form-7/#comments</comments>
		<pubDate>Thu, 16 May 2013 02:55:27 +0000</pubDate>
		<dc:creator>Grant</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://grantpalin.com/?p=2667</guid>
		<description><![CDATA[<p>On most sites, a means of contacting the site's webmaster or owner is essential. Sites built on WordPress have a number of options for managing contact forms; a popular choice is Contact Form 7, which will be the focus of a walkthrough here.</p><p>The post <a href="http://grantpalin.com/2013/05/15/extending-wordpress-contact-forms-with-contact-form-7/">Extend WordPress &#8211; Contact Forms with Contact Form 7</a> appeared first on <a href="http://grantpalin.com">GrantPalin.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>A common fixture on websites is a contact page, which provides the means for visitors to send a message to the site owner or administrator, whether a question, comment, compliment&#8230; or complaint, as the case may be. The simplest way to do this is by creating a <code>mailto</code> hyperlink with the destination email address, but this leads to at least two problems:</p>
<ul>
<li>the user experience is marred by having to open a mail client, paste the address and type a message, or clicking on the link, having the mail client appear, and typing a message.</li>
<li>an email address embedded into a page&#8217;s markup becomes a target for email harvesters, which trawl the web looking for unprotected email addresses that they can then spam.</li>
</ul>
<p>There are technical solutions to avoid the email harvesters, but this still leaves the user experience issue on the table. Fortunately, there is another option which addresses both issues: contact forms.</p>
<p>A contact form makes use of HTML form elements to present some form fields for the user to fill out, and a button to submit the message. There&#8217;s usually some validation, client side and/or server-side, to ensure the form is filled out correctly, and some styling to make the form appealing to the eye. No need to involve an email client, and no vulnerable email addresses for harvesters to catch.</p>
<p>This can be prepared manually by a developer, but a savvy WordPress webmaster can use a plugin to handle the details. This is where <strong>Contact Form 7</strong> comes in.</p>
<p>The bulk of this article will be a tour through Contact Form 7&#8242;s creation, editing, and modification processes. The tour will be followed by a section covering some slightly advanced steps that can be taken to further enhance the form. But first, an introduction.</p>
<h2>Introducing Contact Form 7</h2>
<p><a href="http://contactform7.com/">Contact Form 7</a> (<abbr title="Contact Form 7">CF7</abbr>) is a popular plugin which simplifies contact form creation to a matter of clicks in the WordPress backend, and pasting a shortcode into the desired location for the form to appear.</p>
<p>In short, <abbr title="Contact Form 7">CF7</abbr> has the following notable features:</p>
<ul>
<li>allows custom styling</li>
<li>can check submissions for spam</li>
<li>supports validation for:
<ul>
<li>required elements</li>
<li>input formats</li>
<li>content length limits</li>
</ul>
</li>
<li>supports CAPTCHA</li>
<li>AJAX-based submissions</li>
<li>extensibility via hooks</li>
<li>HTML5 form elements and attributes</li>
</ul>
<p>At the time of writing, the current version is 3.4, published on April 8, 2013. The plugin has almost 10.4 million downloads. This is a major update, several months after the previous major revision. A notable improvement is support for HTML5 form elements and attributes.</p>
<p>The next section is a tour of <abbr title="Contact Form 7">CF7</abbr>&#8216;s features, as well as the creation of a basic contact form.</p>
<h2>Tour of Contact Form 7</h2>
<p>This plugin is available <a href="http://wordpress.org/extend/plugins/contact-form-7/">in the WordPress plugin repository</a>, and can be brought into play by the standard download-install-activate dance. Once activated, the plugin shows an entry in the WordPress admin menu:</p>
<img src="http://grantpalin.com/wp-content/uploads/2013/05/wp-admin-contact-link.png" alt="Contact Form 7 adds a Contact item to the dashboard menu" class="size-full wp-image-2785" />
<p>Hitting that link sends the user to the <abbr title="Contact Form 7">CF7</abbr> administration page:</p>
<img src="http://grantpalin.com/wp-content/uploads/2013/05/cf7-page-initial-view-800x398.png" alt="The first time up, the Contact Form 7 screen has one default form" class="size-wide wp-image-2783" />
<p>The plugin automatically creates a basic contact form. Note that the <strong>Add New</strong> button at the top of the page allows creation of multiple contact forms. The default form can be edited by clicking the form title; doing so brings up the form editor. It&#8217;s a rather long page at the outset, though the individual sections can be collapsed, expanded, and moved in a manner similar to the WordPress dashboard. Each section will be examined in succession, starting at the top.</p>
<h3>Title</h3>
<img src="http://grantpalin.com/wp-content/uploads/2013/05/cf7-page-form-title-shortcode-800x159.png" alt="When editing a single form, the form title and shortcode appear at top" class="size-wide wp-image-2781" />
<p>The topmost section contains the form&#8217;s title. This is more for management through the backend than anything else. The title can be clicked on to modify it; click on the nearby <strong>Save</strong> button within the box after doing so. Note the boxed-in text below the form title: this is the shortcode that can be pasted into one of the site&#8217;s content sections to show the form.</p>
<h3>Form</h3>
<img src="http://grantpalin.com/wp-content/uploads/2013/05/cf7-page-form-form-800x451.png" alt="The form editor takes markup and CF7 shortcodes" class="size-wide wp-image-2777" />
<p>The textarea on the left takes a combination of markup and shortcodes. This setup allows full customization of the markup that goes into a form. The shortcodes are local to the <abbr title="Contact Form 7">CF7</abbr> plugin &#8211; they are placed where corresponding HTML elements are to appear when the form is rendered on a page. The asterisk (<code>*</code>) adjacent to the element type indicates that the field is required; if the asterisk is omitted, the field is considered optional.</p>
<p>The contents of the default form are:</p>
<pre><code>&lt;p&gt;Your Name (required)&lt;br /&gt;[text* your-name]&lt;/p&gt;

&lt;p&gt;Your Email (required)&lt;br /&gt;[email* your-email]&lt;/p&gt;

&lt;p&gt;Subject&lt;br /&gt;[text your-subject]&lt;/p&gt;

&lt;p&gt;Your Message&lt;br /&gt;[textarea your-message]&lt;/p&gt;

&lt;p&gt;[submit "Send"]&lt;/p&gt;
</code></pre>
<p>The <a href="http://contactform7.com/tag-syntax/">shortcode syntax is well-detailed</a> on the plugin&#8217;s website. Take a look for the full details, but in short, shortcodes can also specify content length, id, and class attributes.</p>
<p>Also observe the dropdown box at right; it contains items that, when clicked, will cause appropriate shortcodes to appear in the textarea at left. There&#8217;s a good number to choose from, covering most typical contact form elements. The choices include:</p>
<ul>
<li>text fields, including email, URL, telephone, date</li>
<li>textareas</li>
<li>select lists</li>
<li>check boxes</li>
<li>radio buttons</li>
<li>file upload</li>
<li>captcha</li>
<li>quiz</li>
<li>acceptance checkbox</li>
<li>submit button</li>
</ul>
<p>A notable addition here is the support for HTML5 form elements, a worthwhile component of the ever-evolving HTML specification.</p>
<p>The form is currently pretty straightforward and typical for a contact form. There is more that can be done, but the default will do for now.</p>
<h3>Mail</h3>
<img src="http://grantpalin.com/wp-content/uploads/2013/05/cf7-page-form-mail-800x376.png" alt="Edit settings for the sending of an email" class="size-wide wp-image-2778" />
<p>The next section down is for <strong>Mail</strong> settings. The data entered here represent various details around the sending of an email:</p>
<ul>
<li>to</li>
<li>from</li>
<li>subject</li>
<li>additional headers</li>
<li>file attachments</li>
<li>content type</li>
</ul>
<p>Of interest is the ability to specify additional headers for email messages. One such possibility is CC-ing the message to another recipient; BCC is also an option. The values for these can be hard-coded here, or they can retrieve values from fields listed in the previous section. This field is <a href="http://contactform7.com/adding-cc-bcc-and-other-mail-headers/">documented briefly</a> on the plugin website.</p>
<p>It is also possible to specify the body of the email, including the submitter&#8217;s message, in the nearby textarea:</p>
<pre><code>From: [your-name] &lt;[your-email]&gt;
Subject: [your-subject]

Message Body:
[your-message]

--
This mail is sent via contact form on [sitename] [site-address]
</code></pre>
<p>The <code>[site-name]</code> and <code>[site-address]</code> items above are placeholders written for this example; the plugin automatically uses the site name and address from the WordPress settings on this line.</p>
<p>There are a number of shortcodes available here, based on which fields are added in the <strong>form</strong> section shown earlier. With the default form, the following shortcodes are available:</p>
<ul>
<li><code>[your-name]</code> &#8211; submitter&#8217;s name</li>
<li><code>[your-email]</code> &#8211; submitter&#8217;s email address</li>
<li><code>[your-subject]</code> &#8211; message&#8217;s subject</li>
<li><code>[your-message]</code> &#8211; message content</li>
</ul>
<p>The shortcode names here match the names assigned to the form elements previously.</p>
<p>One last thing to note: there are <a href="http://contactform7.com/special-mail-tags/">additional shortcodes</a> that can be referenced within this section. These include the URL of the contact form, the submitter&#8217;s IP address, and the date and time of submission, among other things.</p>
<h3>Mail (2)</h3>
<img src="http://grantpalin.com/wp-content/uploads/2013/05/cf7-page-form-mail-2-800x429.png" alt="These settings can be used to send a copy of the submission to another recipient, or even to the submitter" class="size-wide wp-image-2779" />
<p>Continuing on, the <strong>Mail (2)</strong> section provides the ability to send a copy of the email to a separate recipient. Checking the <strong>Use mail (2)</strong> checkbox will reveal form fields similar to the <strong>Mail</strong> section already covered. Same fields, same shortcodes. This could be useful for sending a copy of the message to the submitter&#8217;s email. The author notes that this second message is only sent if the initial one succeeds.</p>
<h3>Messages</h3>
<img src="http://grantpalin.com/wp-content/uploads/2013/05/cf7-page-form-messages-800x392.png" alt="CF7 provides the ability to customize numerous different status messages" class="size-wide wp-image-2780" />
<p>Part of a good form experience is providing feedback to the user. Such feedback can be varied, but often includes a notice of successful submission, a notice of errors in the entered data, or notice of a failed challenge response. <abbr title="Contact Form 7">CF7</abbr> supports the following message types:</p>
<ul>
<li>success</li>
<li>failure</li>
<li>validation errors</li>
<li>spam submission</li>
<li>must accept terms</li>
<li>required field</li>
<li>invalid CAPTCHA response</li>
<li>invalid date format</li>
<li>date too early</li>
<li>date too late</li>
<li>file upload failure</li>
<li>file type invalid</li>
<li>file too large</li>
<li>file upload fails &#8211; PHP error</li>
<li>number format invalid</li>
<li>number smaller than minimum</li>
<li>number larger than maximum</li>
<li>incorrect quiz response</li>
<li>email address is invalid</li>
<li>URL is invalid</li>
<li>telephone number is invalid</li>
</ul>
<p>That&#8217;s 21 different notice types. Some of them are related, such as those pertaining to file uploads, but still, this provides for a lot of flexibility. Default text is provided for each notice type; these defaults can be kept as they are, or can be individually edited. Interestingly, these fields support the use of basic HTML, so it is possible to add text formatting, links, and even images to the generated notice.</p>
<h3>Additional Settings</h3>
<img src="http://grantpalin.com/wp-content/uploads/2013/05/cf7-page-form-additional-settings-800x200.png" alt="This field is for miscellaneous settings" class="size-wide wp-image-2776" />
<p>It&#8217;s not obvious what this field can be used for. Supposedly it&#8217;s intended as a catch-all for other settings that do not fit in any of the previous section. The plugin author has provided a usage example: <a href="http://contactform7.com/tracking-form-submissions-with-google-analytics/">tracking contact form submissions</a> with Google Analytics.</p>
<p>Short any similar needs, this field can likely be left blank.</p>
<h3>Basic Form Demo</h3>
<p>Having completed the basic tour, the form is ready to be used. This is simple: copy the form shortcode listed at the top of the form page, just below the title, paste it in any page or post, and save. Viewing said page or post should make the form appear. Here&#8217;s what the default form looks like on the Twenty Twelve theme, with validation errors visible:</p>
<img src="http://grantpalin.com/wp-content/uploads/2013/05/cf7-contact-form-default.png" alt="The default form only has two required fields, and some other issues" class="size-full wp-image-2774" />
<p>It&#8217;s not overly pretty, but is functional. For allowing site visitors to contact the site owner or administrator, this form is as simple as it gets. There&#8217;s more that can be done, however. Additional topics are addressed in the next section.</p>
<h2>Advanced Form Management</h2>
<h3>Labels</h3>
<p>An issue with the default form, and the shortcodes, is that they don&#8217;t include <code>label</code> elements corresponding to the individual input elements. Such labels are useful for accessibility and usability, since they provide cues to the user that a label is associated with an input element, and the label can be clicked to set the focus on the matching element &#8211; especially useful for otherwise small targets such as checkboxes.</p>
<p>There are two ways to make this association: wrap the <code>label</code> around the input, which implicitly creates the association, or use the label&#8217;s <code>for</code> attribute to specify which input to match; the value of the label&#8217;s <code>for</code> attribute must match the <code>id</code> attribute of the matching input element. The following implementation will use the latter technique, though the former could work just as well.</p>
<p>According to the <a href="http://contactform7.com/tag-syntax/">syntax reference</a>, adding an <code>id</code> attribute to an input element is done by adding the same to an element shortcode. The form markup can be revised as:</p>
<pre><code>&lt;p&gt;&lt;label for="your-name"&gt;Name&lt;/label&gt;&lt;br /&gt;[text* your-name id:your-name]&lt;/p&gt;

&lt;p&gt;&lt;label for="your-email"&gt;Email&lt;/label&gt;&lt;br /&gt;[email* your-email id:your-email]&lt;/p&gt;

&lt;p&gt;&lt;label for="your-subject"&gt;Subject&lt;/label&gt;&lt;br /&gt;[text* your-subject id:your-subject]&lt;/p&gt;

&lt;p&gt;&lt;label for="your-message"&gt;Message&lt;/label&gt;&lt;br /&gt;[textarea* your-message id:your-message]&lt;/p&gt;

&lt;p&gt;[submit "Send"]&lt;/p&gt;
</code></pre>
<p>This implementation has added the <code>label</code> elements, and removed the <strong>(required)</strong> bits since they were redundant, with every field now being required. The next screenshot shows the revised form, with all the validation errors visible:</p>
<img src="http://grantpalin.com/wp-content/uploads/2013/05/cf7-contact-form-revised.png" alt="The modified form has all fields as required, and simplified labels" class="size-full wp-image-2775" />
<p>The labels can be clicked to set the focus on their matching form fields; the form also requires that all fields be filled in before submission.</p>
<p>The validation errors don&#8217;t stand out too much, and could use some enhancement. Also, the labels aren&#8217;t obviously labels &#8211; they look like raw text above each field. There should be a cue to the user that labels are clickable to set focus on the matching fields. These are styling issues, which will be examined in a little more detail at another time.</p>
<h3>Controlling Scripts and Stylesheets</h3>
<p>By default, <abbr title="Contact Form 7">CF7</abbr> automatically loads it&#8217;s own custom script and stylesheet files into the page header, for each page. This is needless for pages that do not have a contact form. According to the plugin author, there isn&#8217;t an easy way to detect whether a contact form is present on a page when that page starts loading. The workaround is to disable automatic script/style loading, and to only load these files on pages where it is known that they are needed. Such as, say, a contact page&#8230;</p>
<p>The <abbr title="Contact Form 7">CF7</abbr> website provides <a href="http://contactform7.com/loading-javascript-and-stylesheet-only-when-it-is-necessary/">information on handling this scenario</a>. The long and short of it is adding the following lines to the site&#8217;s <code>wp-config.php</code> file:</p>
<pre><code>define('WPCF7_LOAD_JS', false);
define('WPCF7_LOAD_CSS', false);
</code></pre>
<p>These values default to <code>true</code>; setting them to <code>false</code> prevents autoloading of the script and style files. The next step is to add the following to a template for the contact page:</p>
<pre><code>&lt;?php
if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
    wpcf7_enqueue_scripts();
    wpcf7_enqueue_styles();
}
?&gt;
</code></pre>
<p>This will cause the files to be specifically requested for the one page. This assumes that there is only one page hosting a contact form; more involved solutions may be needed where contact forms may be used in multiple places on a website, but this technique shows how it can be done.</p>
<h3>Avoiding Spam</h3>
<p>As much as a contact form avoids the problem of bots harvesting email addresses, the form itself can be subject to automated spam submissions. There&#8217;s also nothing preventing humans from manually submitting spam. There are two techniques that can be applied to address both problems, discussed next.</p>
<h4>Honeypots</h4>
<p>To address the first issue, it&#8217;s worthwhile to make use of a <em>honeypot</em> on the form. A honeypot attracts spam bots, which then submit spam in the form, and the submission can be summarily dropped. This works because bots are dumb, and they try to fill in every field in a form before submitting it. The actual honeypot is a hidden field, which a human would not see or fill in, but for which a bot will happily submit a value. Thus, when the submission system detects that the honeypot field has been given a value, the submission is considered spam and can be dropped.</p>
<p>This technique can be implemented by a plugin to supplement the capabilities of Contact Form 7. The plugin is <a href="http://www.daobydesign.com/free-plugins/honeypot-module-for-contact-form-7-wordpress-plugin">Contact Form 7 Honeypot</a>, and is freely available on <a href="http://wordpress.org/extend/plugins/contact-form-7-honeypot/">the WordPress plugin repository</a>. No configuration is needed after activation. Just return to the form editing view and activate the <strong>Generate Tag</strong> dropdown &#8211; there should be a new <strong>Honeypot</strong> option, as shown below.</p>
<img src="http://grantpalin.com/wp-content/uploads/2013/05/cf7-page-tag-menu-honeypot-800x453.png" alt="Can add a honeypot to the form to deter automated submissions" class="size-wide wp-image-2784" />
<p>Selecting the <strong>Honeypot</strong> option brings up a settings view, which just asks for a name to assign to the field. The recommendation is to make it a random string so it can&#8217;t be guessed by bots. Then just copy the provided shortcode and paste it into the form content area.</p>
<img src="http://grantpalin.com/wp-content/uploads/2013/05/cf7-page-honeypot-name-800x453.png" alt="A shortcode must be added to the form to include the honeypot" class="size-wide wp-image-2782" />
<p>After the honeypot addition, the form content resembles the following:</p>
<pre><code>&lt;p&gt;&lt;label for="your-name"&gt;Name&lt;/label&gt;&lt;br /&gt;[text* your-name id:your-name]&lt;/p&gt;

&lt;p&gt;&lt;label for="your-email"&gt;Email&lt;/label&gt;&lt;br /&gt;[email* your-email id:your-email]&lt;/p&gt;

&lt;p&gt;&lt;label for="your-subject"&gt;Subject&lt;/label&gt;&lt;br /&gt;[text* your-subject id:your-subject]&lt;/p&gt;

&lt;p&gt;&lt;label for="your-message"&gt;Message&lt;/label&gt;&lt;br /&gt;[textarea* your-message id:your-message]&lt;/p&gt;

[honeypot honeypot-268]

&lt;p&gt;[submit "Send"]&lt;/p&gt;
</code></pre>
<p>Refreshing the page or post the form is located on, then examining the source, reveals an added section of the form:</p>
<pre><code>&lt;p&gt;
  &lt;span class="wpcf7-form-control-wrap hiddenhoneypot-268" style="display:none;"&gt;
    &lt;label for="email-wpcf7-hp"&gt;&lt;small&gt;Leave this field empty.&lt;/small&gt;&lt;/label&gt;
    &lt;input class="wpcf7-text" type="text" name="email-wpcf7-hp" id="email-wpcf7-hp" value="" size="40" tabindex="3"&gt;
  &lt;/span&gt;
&lt;/p&gt;
</code></pre>
<p>Most humans won&#8217;t see the field, as it is hidden from view. Bots will attempt to fill in the field and include it in the form submission. Because the system knows that field should not have a value, the submission can be discarded, and the page will return a submission failure notice.</p>
<p>Another common option for defeating spam bots is the use of CAPTCHAs. While this route may be effective against bots, it also introduces usability issues for genuine users. The honeypot solution is invisible to humans, and is targeted specifically at bots.</p>
<h4>Filtering Submissions</h4>
<p>While the honeypot solution may effectively deter bots making automated submissions, it does nothing to prevent humans from manually submitting spam. Fortunately, there is a countermeasure for this built into <abbr title="Contact Form 7">CF7</abbr>.</p>
<p>WordPress has for quite some time worked closely with the <a href="http://akismet.com/">Akismet</a> service to check comment submissions for spam. This functionality is not specific to checking comments, and it can be leveraged to check contact form submissions as well.</p>
<p>This functionality is <a href="http://contactform7.com/spam-filtering-with-akismet/">documented on the <abbr title="Contact Form 7">CF7</abbr> site</a>; an excerpt follows:</p>
<blockquote>
<ul>
<li><code>akismet:author</code><br />Add this option to the field that accepts the name of the sender.<br />Example: <code>[text* your-name akismet:author]</code>
<ul>
<li><code>akismet:author_email</code><br />Add this option to the field that accepts the email address of the sender.<br />Example: <code>[email* your-email akismet:author_email]</code></li>
<li><code>akismet:author_url</code><br />Add this option to the field that accepts the URL of the sender.<br />Example: <code>[text your-url akismet:author_url]</code></li>
</ul>
</li>
</ul>
</blockquote>
<p>If WordPress is already configured to use Akismet (and why wouldn&#8217;t it be?!), then there&#8217;s just a small change to make to the form content. The <code>akismet:...</code> snippets need to be grafted into the existing element shortcodes. Continuing with the running example, the updated form content looks like this:</p>
<pre><code>&lt;p&gt;&lt;label for="your-name"&gt;Name&lt;/label&gt;&lt;br /&gt;[text* your-name akismet:author id:your-name]&lt;/p&gt;

&lt;p&gt;&lt;label for="your-email"&gt;Email&lt;/label&gt;&lt;br /&gt;[email* your-email akismet:author_email id:your-email]&lt;/p&gt;

&lt;p&gt;&lt;label for="your-subject"&gt;Subject&lt;/label&gt;&lt;br /&gt;[text* your-subject id:your-subject]&lt;/p&gt;

&lt;p&gt;&lt;label for="your-message"&gt;Message&lt;/label&gt;&lt;br /&gt;[textarea* your-message id:your-message]&lt;/p&gt;

[honeypot honeypot-268]

&lt;p&gt;[submit "Send"]&lt;/p&gt;
</code></pre>
<p>There are only options for author name, email, and URL, but only one of them needs to be implemented to cause the whole submission to go through the Akismet filtering process; it is recommended to use all available options where appropriate to maximize accuracy.</p>
<p>The analysis is done on submission; if the submission passes Akismet, the email will be sent to the intended recipient. If the submission does not pass, it will not be emailed, and a submission failure message will appear.</p>
<h2>Things to Consider</h2>
<p><abbr title="Contact Form 7">CF7</abbr> provides a number of hooks and filters, making this simple form system quite extensible. There are in fact other plugins available to expand <abbr title="Contact Form 7">CF7</abbr>&#8216;s capabilities. This is part of what makes the WordPress ecosystem so attractive.</p>
<p>The plugin&#8217;s default styling is spartan, and may not fit with existing themes. This is briefly mentioned earlier, but it is possible to write custom styles. More on this later!</p>
<p><abbr title="Contact Form 7">CF7</abbr> is pretty flexible; with the elements it supports and the automated processing it can do, along with further extensibility, much more can be done than just contact forms. Ideas that come to mind include project quote forms, polls or surveys, and registration forms. It&#8217;s even possible to save the form data rather than emailing it &#8211; see the <a href="http://wordpress.org/extend/plugins/flamingo/description/">Flamingo</a> plugin, also by the creator of <abbr title="Contact Form 7">CF7</abbr>. There is a <a href="http://wordpress.org/extend/plugins/contact-form-7-to-database-extension/">similar plugin available</a> to save submissions to the database.</p>
<h2>Conclusion</h2>
<p>Contact Form 7 is widely used, intuitive, and extensible, not to mention current with the times. For the majority of contact forms, which as a whole tend to be straightforward, there probably couldn&#8217;t be a simpler way to create as many contact forms as are needed. They can be similar or wildly different, as each can be managed separately. The built-in shortcodes and validation messages are diverse and will cover most typical scenarios.</p>
<p>For now, <abbr title="Contact Form 7">CF7</abbr> looks like the go-to option for any manner of contact, or similar, forms.</p>
<h2>Additional Reading</h2>
<p>Linked below are some additional resources on using <abbr title="Contact Form 7">CF7</abbr>. Enjoy!</p>
<ul>
<li><a href="http://wp.tutsplus.com/tutorials/plugins/mini-guide-to-contact-form-7/">Mini Guide to Contact Form 7</a></li>
<li><a href="http://contactform7.com/docs/">Contact Form 7 Docs</a></li>
<li><a href="http://contactform7.com/faq/">Contact Form 7 FAQs</a></li>
</ul>
<p>The post <a href="http://grantpalin.com/2013/05/15/extending-wordpress-contact-forms-with-contact-form-7/">Extend WordPress &#8211; Contact Forms with Contact Form 7</a> appeared first on <a href="http://grantpalin.com">GrantPalin.com</a>.</p><img src="http://feeds.feedburner.com/~r/grantpalin/~4/9_LLnG9qGaY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://grantpalin.com/2013/05/15/extending-wordpress-contact-forms-with-contact-form-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Capsule, The Developer’s Code Journal</title>
		<link>http://grantpalin.com/2013/04/25/capsule-the-developers-code-journal/</link>
		<comments>http://grantpalin.com/2013/04/25/capsule-the-developers-code-journal/#comments</comments>
		<pubDate>Fri, 26 Apr 2013 04:05:14 +0000</pubDate>
		<dc:creator>Grant</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://grantpalin.com/?p=2695</guid>
		<description><![CDATA[<p>Capsule is a WordPress theme spearheaded by Alex King, a prolific WordPress user and developer. The premise behind Capsule is to provide a purpose-built system for coders to maintain programming notes, knowledge, and snippets in a WordPress-based application. Very neat!</p><p>The post <a href="http://grantpalin.com/2013/04/25/capsule-the-developers-code-journal/">Capsule, The Developer’s Code Journal</a> appeared first on <a href="http://grantpalin.com">GrantPalin.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><a href="http://crowdfavorite.com/capsule/">Capsule</a> is a WordPress theme spearheaded by <a href="http://alexking.org/">Alex King</a>, a prolific WordPress user and developer. The premise behind Capsule is to provide a purpose-built system for coders to maintain programming notes, knowledge, and snippets in a WordPress-based application. Very neat!</p>
<p>The post <a href="http://grantpalin.com/2013/04/25/capsule-the-developers-code-journal/">Capsule, The Developer’s Code Journal</a> appeared first on <a href="http://grantpalin.com">GrantPalin.com</a>.</p><img src="http://feeds.feedburner.com/~r/grantpalin/~4/vf6yEQi9KJE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://grantpalin.com/2013/04/25/capsule-the-developers-code-journal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WP Test – The Best Tests For WordPress</title>
		<link>http://grantpalin.com/2013/03/19/wp-test-the-best-tests-for-wordpress/</link>
		<comments>http://grantpalin.com/2013/03/19/wp-test-the-best-tests-for-wordpress/#comments</comments>
		<pubDate>Wed, 20 Mar 2013 05:51:46 +0000</pubDate>
		<dc:creator>Grant</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://grantpalin.com/?p=2618</guid>
		<description><![CDATA[<p>A suite of test data for WordPress, to be used for testing theme appearance and behaviour. Builds on WordPress&#8217; own theme test data with years of personal experience to &#8220;create a potent cocktail of simulated, quirky user content&#8221;. Looks like another worthwhile tool in the theme development toolbox.</p><p>The post <a href="http://grantpalin.com/2013/03/19/wp-test-the-best-tests-for-wordpress/">WP Test &#8211; The Best Tests For WordPress</a> appeared first on <a href="http://grantpalin.com">GrantPalin.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>A suite of test data for WordPress, to be used for testing theme appearance and behaviour. Builds on <a href="http://codex.wordpress.org/Theme_Unit_Test">WordPress&#8217; own theme test data</a> with years of personal experience to &#8220;create a potent cocktail of simulated, quirky user content&#8221;. Looks like another worthwhile tool in the theme development toolbox.</p>
<p>The post <a href="http://grantpalin.com/2013/03/19/wp-test-the-best-tests-for-wordpress/">WP Test &#8211; The Best Tests For WordPress</a> appeared first on <a href="http://grantpalin.com">GrantPalin.com</a>.</p><img src="http://feeds.feedburner.com/~r/grantpalin/~4/f_14xAmGJxY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://grantpalin.com/2013/03/19/wp-test-the-best-tests-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Review: Markdown by Example</title>
		<link>http://grantpalin.com/2013/03/17/review-markdown-by-example/</link>
		<comments>http://grantpalin.com/2013/03/17/review-markdown-by-example/#comments</comments>
		<pubDate>Sun, 17 Mar 2013 07:07:40 +0000</pubDate>
		<dc:creator>Grant</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[Markdown]]></category>

		<guid isPermaLink="false">http://grantpalin.com/?p=2599</guid>
		<description><![CDATA[<p>Author: Tim SteinbachPublisher: LeanpubPublished: 2012Pages: 214 Introduction I got my first experience with using Markdown close to a year ago, and wrote about what I had learned so far a few months ago. While Markdown isn&#8217;t a complex topic, I still wanted to have a tutorial to go through, since the official documentation is more [...]</p><p>The post <a href="http://grantpalin.com/2013/03/17/review-markdown-by-example/">Review: Markdown by Example</a> appeared first on <a href="http://grantpalin.com">GrantPalin.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>
<figure class="image medium float-left"><a href="https://leanpub.com/markdown"><img src="http://grantpalin.com/wp-content/uploads/2013/03/cover-markdown-by-example-129x200.png" alt="Cover - Markdown by Example" class="alignnone size-medium wp-image-2601" /></a></figure>
</p>
<p><strong>Author:</strong> Tim Steinbach<br /><strong>Publisher:</strong> Leanpub<br /><strong>Published:</strong> 2012<br /><strong>Pages:</strong> 214</p>
<h2>Introduction</h2>
<p>I got my first experience with using Markdown close to a year ago, and <a href="http://grantpalin.com/2012/09/10/more-efficient-markup-with-markdown/">wrote about</a> what I had learned so far a few months ago. While Markdown isn&#8217;t a complex topic, I still wanted to have a tutorial to go through, since the official documentation is more of a reference. After some searching, I found <a href="https://leanpub.com/markdown">Markdown by Example</a>.</p>
<h2>The Markdown Breakdown</h2>
<p>The book is broken down into three main sections, each with multiple chapters, and an appendix. The first section introduces Markdown, its origin and intent, available editors, installation of supporting software, and references to the book website and code samples. The installation sections covered OS X and Linux &#8211; Windows was noticeably absent.</p>
<p>The middle section has two chapters: one for learning the Markdown syntax &#8211; it really is simple and straightforward, only one chapter is needed! &#8211; and one for a syntax reference. The latter chapter surprised me, coming directly after the instructional chapter; since it is a reference, I thought it might be better located at the back of the book, in the appendix, rather than in the middle, or even as a separate printable PDF.</p>
<p>Markdown is such a simple syntax that it hardly needed any coverage &#8211; really, just one chapter to provide the syntax details! However, the meat of the book follows in the third section. This section consists of twelve chapters, covering numerous uses of Markdown for different purposes. These examples include generating HTML output, building websites and blogs, building presentations, writing for WordPress and Wikis, and writing books. That last one, on writing books with Markdown, illustrates how the author prepared this very book and collaborated with Leanpub. It goes to show that for a knowledgeable person who enjoys writing, self-publishing is in reach with publishers like Leanpub and tools such as Markdown!</p>
<p>One other thing of interest is that Markdown is at its heart quite basic and simple &#8211; it&#8217;s great for text formatting, inserting links, and basic document layout. It does not, however, provide for document elements such as tables, footnotes, and mathematical formulae. There are some extended Markdown implementations out there which to some extent provide functionality beyond the core syntax; the book covers two in particular, namely, GitHub-flavoured Markdown and MultiMarkdown. I&#8217;m aware of at least one other, Markdown Extra, so was a little surprised it didn&#8217;t receive any coverage like the other two.</p>
<p>The book&#8217;s <a href="http://nequissimus.github.com/MarkdownByExample/" class="broken_link">companion website</a> has links to purchasing printed and electronic copies, a book wiki, and a repository of code samples shown and referenced in the book.</p>
<h2>Conclusion</h2>
<p>Overall, the book is concise and well-written. I have minor issue with the placement of the reference chapter, as well as the incomplete coverage of the Markdown supersets. Combined with the provided code samples, there&#8217;s much here to get a Markdown novice underway!</p>
<p><strong>The bottom line:</strong> Markdown by Example is a worthwhile and inexpensive read for anyone wanting a gentle introduction to the Markdown format, as well as its possible applications. I recommend it for any Markdown beginner.</p>
<p>The post <a href="http://grantpalin.com/2013/03/17/review-markdown-by-example/">Review: Markdown by Example</a> appeared first on <a href="http://grantpalin.com">GrantPalin.com</a>.</p><img src="http://feeds.feedburner.com/~r/grantpalin/~4/f2Val0HVaHs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://grantpalin.com/2013/03/17/review-markdown-by-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to lose weight (in the browser)</title>
		<link>http://grantpalin.com/2013/03/14/how-to-lose-weight-in-the-browser/</link>
		<comments>http://grantpalin.com/2013/03/14/how-to-lose-weight-in-the-browser/#comments</comments>
		<pubDate>Thu, 14 Mar 2013 19:39:02 +0000</pubDate>
		<dc:creator>Grant</dc:creator>
				<category><![CDATA[Internet]]></category>

		<guid isPermaLink="false">http://grantpalin.com/?p=2593</guid>
		<description><![CDATA[<p>This whimsically-titled page is in fact a concise resource for web developers. It covers numerous ways to optimize webpages for weight and speed, and is broken down into the following subtopics: markup scripts styles images server configuration testing tools Optimization can seem like a dry subject, but this resource really simplifies the subject, pointing out [...]</p><p>The post <a href="http://grantpalin.com/2013/03/14/how-to-lose-weight-in-the-browser/">How to lose weight (in the browser)</a> appeared first on <a href="http://grantpalin.com">GrantPalin.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>This whimsically-titled page is in fact a concise resource for web developers. It covers numerous ways to optimize webpages for weight and speed, and is broken down into the following subtopics:</p>
<ul>
<li>markup</li>
<li>scripts</li>
<li>styles</li>
<li>images</li>
<li>server configuration</li>
<li>testing tools</li>
</ul>
<p>Optimization can seem like a dry subject, but this resource really simplifies the subject, pointing out the simple ways to make gains on page size and speed. Low-hanging fruit perhaps, but even those can add up!</p>
<p>The post <a href="http://grantpalin.com/2013/03/14/how-to-lose-weight-in-the-browser/">How to lose weight (in the browser)</a> appeared first on <a href="http://grantpalin.com">GrantPalin.com</a>.</p><img src="http://feeds.feedburner.com/~r/grantpalin/~4/WCudbKpWLaw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://grantpalin.com/2013/03/14/how-to-lose-weight-in-the-browser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Community Resource Library – Help Us Build It!</title>
		<link>http://grantpalin.com/2013/03/12/the-community-resource-library-help-us-build-it/</link>
		<comments>http://grantpalin.com/2013/03/12/the-community-resource-library-help-us-build-it/#comments</comments>
		<pubDate>Wed, 13 Mar 2013 03:54:36 +0000</pubDate>
		<dc:creator>Grant</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://grantpalin.com/?p=2589</guid>
		<description><![CDATA[<p>The WP Daily website has been growing and noticeably active in recent times. One of its latest initiatives is the creation and curation of a library of WordPress-related resources. These run the gamut from news to tutorials to podcasts, touching on numerous subjects over varied media. This is a welcome initiative because, as powerful as [...]</p><p>The post <a href="http://grantpalin.com/2013/03/12/the-community-resource-library-help-us-build-it/">The Community Resource Library &#8211; Help Us Build It!</a> appeared first on <a href="http://grantpalin.com">GrantPalin.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>The WP Daily website has been growing and noticeably active in recent times. One of its latest initiatives is the creation and curation of a library of WordPress-related resources. These run the gamut from news to tutorials to podcasts, touching on numerous subjects over varied media.</p>
<p>This is a welcome initiative because, as powerful as search engines are today, finding relevant, useful, <strong>and</strong> quality content can still be a challenge for <em>any</em> subject. WP Daily are taking a step to bridging that gap with their Community Resource Library initiative.</p>
<p>The post <a href="http://grantpalin.com/2013/03/12/the-community-resource-library-help-us-build-it/">The Community Resource Library &#8211; Help Us Build It!</a> appeared first on <a href="http://grantpalin.com">GrantPalin.com</a>.</p><img src="http://feeds.feedburner.com/~r/grantpalin/~4/8KSBs4mAQpI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://grantpalin.com/2013/03/12/the-community-resource-library-help-us-build-it/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress Theming – Templates and Subdirectories</title>
		<link>http://grantpalin.com/2013/02/13/wordpress-theming-templates-and-subdirectories/</link>
		<comments>http://grantpalin.com/2013/02/13/wordpress-theming-templates-and-subdirectories/#comments</comments>
		<pubDate>Thu, 14 Feb 2013 05:51:13 +0000</pubDate>
		<dc:creator>Grant</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://grantpalin.com/?p=2547</guid>
		<description><![CDATA[<p>WordPress templates allow for the use of numerous template files; when used, these files can clutter up a theme's root directory. WordPress allows organizing files into subdirectories to keep things tidy; this post shows how to do it.</p><p>The post <a href="http://grantpalin.com/2013/02/13/wordpress-theming-templates-and-subdirectories/">WordPress Theming &#8211; Templates and Subdirectories</a> appeared first on <a href="http://grantpalin.com">GrantPalin.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<h2>Introduction</h2>
<p><a href="http://grantpalin.com/2013/02/12/wordpress-theming-partial-templates-with-get_template_part/">A previous post on template partials</a> showed how to componentize a theme by breaking out reusable blocks of code into discrete files, and consume them via the <code>get_template_part()</code> function. This has the potential to lead to numerous &#8220;extra&#8221; files located in the theme root folder beyond the standard theme files. WordPress offers the option to organize template files into subdirectories; this post will continue the example in the previous post and show how to make use of this functionality.</p>
<h2>Template Files in Subdirectories</h2>
<p>As of <a href="http://codex.wordpress.org/Version_3.4">version 3.4</a>, released in mid-2012, WordPress quietly gained the ability to scan a theme&#8217;s subdirectories for template files; this was <a href="http://nacin.com/2012/03/29/page-templates-in-subdirectories-new-in-wordpress-3-4/">initially announced</a> by Andrew Nacin. The scanning is automatic, but to actually consume files within the subdirectories takes just a little work.</p>
<p>As shown previously, basic usage of the <code>get_template_part()</code> function is as follows:</p>
<pre><code>// consume the generalized loop partial
get_template_part('loop');

// consume the author archive-specific loop partial
get_template_part('loop', 'author');
</code></pre>
<p>With partials in a subdirectory, the function usage is largely the same. The difference is that the subdirectory name must be prepended to the partial&#8217;s general name:</p>
<pre><code>// consume the generalized loop partial
get_template_part('partials/loop');

// consume the author archive-specific loop partial
get_template_part('partials/loop', 'author');
</code></pre>
<p>That&#8217;s all it takes!</p>
<h2>Simple Implementation</h2>
<p>The most obvious first step is to create a subdirectory to contain the partials; <code>partials</code> sounds appropriate, so that is what gets used here. Use whichever name seems most appropriate. Then it&#8217;s a simple matter to move the current partials &#8211; namely, <code>loop.php</code> and <code>loop-author.php</code> &#8211; into the subdirectory. The resulting directory and file structure is pictured below.</p>
<div class="image large">
  <img src="http://grantpalin.com/wp-content/uploads/2013/02/partials-subdirectory.png" alt="Partial template files" class="aligncenter size-full wp-image-2551" />Partial template files in partials subdirectory
</div>
<p>Now that the subdirectory has been created and the partials relocated, there&#8217;s some editing to do.</p>
<p>The current theme has a <code>home.php</code> file, which is used for a page set as the posts page in the settings; this file, among other things, has a reference to the <code>loop.php</code> partial, as follows:</p>
<pre><code>get_template_part('loop');
</code></pre>
<p>Since <code>loop.php</code> has been moved to the <code>partials</code> subdirectory, this reference will no longer work; there will be no error shown &#8211; this is by design &#8211; but the file won&#8217;t be loaded or executed. The fix is simple: prepend the subdirectory name to the partial&#8217;s general name, like this:</p>
<pre><code>get_template_part('partials/loop');
</code></pre>
<p>This completes the reference needed for WordPress to do its work. Note that the path is always relative to the theme&#8217;s root directory. The above change may need to be made in the following files, depending on which are being used in the theme:</p>
<ul>
<li><code>archive.php</code></li>
<li><code>author.php</code></li>
<li><code>category.php</code></li>
<li><code>date.php</code></li>
<li><code>home.php</code></li>
<li><code>index.php</code></li>
<li><code>page.php</code></li>
<li><code>single.php</code></li>
<li><code>tag.php</code></li>
</ul>
<p>Following from the example in the previous post, the author archive gets a special treatment. The <code>author.php</code>, contains, among other things, the following line:</p>
<pre><code>get_template_part('loop', 'author');
</code></pre>
<p>Note that the use of the specific name does not change the process used to consume a partial located in a subdirectory; that is, just prepend the subdirectory name to the general partial name:</p>
<pre><code>get_template_part('partials/loop', 'author');
</code></pre>
<p>As shown in the previous post, it&#8217;s not hard to see how this can be used to establish a generalized output pattern for the loop, and then to create specialized versions of the loop for different contexts, as has been done here for the author archive.</p>
<h2>Caveats</h2>
<p>This technique only works one directory deep. WordPress does not scan deeper than one level below the theme root. Also, standard theme files (the ones WordPress automatically uses when present) cannot be relocated into a subdirectory. WordPress might see them, but will not use them. In some cases, an error is shown on the page, in other cases nothing is shown at all. These files include:</p>
<ul>
<li><code>404.php</code></li>
<li><code>archive.php</code></li>
<li><code>attachment.php</code></li>
<li><code>author.php</code></li>
<li><code>category.php</code></li>
<li><code>comments.php</code></li>
<li><code>date.php</code></li>
<li><code>front-page.php</code></li>
<li><code>home.php</code></li>
<li><code>image.php</code></li>
<li><code>index.php</code></li>
<li><code>search.php</code></li>
<li><code>single.php</code></li>
<li><code>page.php</code></li>
<li><code>tag.php</code></li>
</ul>
<h2>Possible Uses</h2>
<p>As has been explained, the loop can be generalized for the common case and specialized for the special cases. All of these fragments can be placed in a single subdirectory to keep the theme root tidy. This can be applied to other types of generalizable content, such as:</p>
<ul>
<li>paging</li>
<li>sidebars</li>
<li>post formats</li>
<li>named page templates</li>
<li>content types, e.g. pages and posts</li>
</ul>
<h2>Conclusion</h2>
<p>It&#8217;s clear that <code>get_template_part()</code> is a very useful function which can modularize themes at the code level. This is further helped by using the subdirectories functionality to organize the resulting partials at the file level. Keeping the theme root as tidy as possible is a good thing; with this technique, only the default files that WordPress expects to see need to be in the theme root.</p>
<h2>Other Reading</h2>
<ul>
<li><a href="http://nacin.com/2012/03/29/page-templates-in-subdirectories-new-in-wordpress-3-4/">Page templates in subdirectories, new in WordPress 3.4</a> (Andrew Nacin)</li>
<li><a href="http://codex.wordpress.org/Function_Reference/get_template_part">get&#95;template&#95;part</a> (WordPress Codex)</li>
</ul>
<p>The post <a href="http://grantpalin.com/2013/02/13/wordpress-theming-templates-and-subdirectories/">WordPress Theming &#8211; Templates and Subdirectories</a> appeared first on <a href="http://grantpalin.com">GrantPalin.com</a>.</p><img src="http://feeds.feedburner.com/~r/grantpalin/~4/6YWBRu8GoFk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://grantpalin.com/2013/02/13/wordpress-theming-templates-and-subdirectories/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Opera to leave Presto, go to Webkit</title>
		<link>http://grantpalin.com/2013/02/13/opera-to-leave-presto-go-to-webkit/</link>
		<comments>http://grantpalin.com/2013/02/13/opera-to-leave-presto-go-to-webkit/#comments</comments>
		<pubDate>Thu, 14 Feb 2013 00:21:55 +0000</pubDate>
		<dc:creator>Grant</dc:creator>
				<category><![CDATA[Web Browsers]]></category>
		<category><![CDATA[Opera]]></category>

		<guid isPermaLink="false">http://grantpalin.com/?p=2540</guid>
		<description><![CDATA[<p>Opera has made a splash in the news by announcing an approaching switch to the WebKit engine. As much of the web community is doing, I share my impressions.</p><p>The post <a href="http://grantpalin.com/2013/02/13/opera-to-leave-presto-go-to-webkit/">Opera to leave Presto, go to Webkit</a> appeared first on <a href="http://grantpalin.com">GrantPalin.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<div class="image medium float-left">
  <img src="http://grantpalin.com/wp-content/uploads/2013/02/opera-and-chromium-200x200.png" alt="Combined Opera and Chromium logos" class="size-medium wp-image-2543" />
</div>
<p>Opera just dropped a bomb on the web developer community: <a href="http://my.opera.com/ODIN/blog/300-million-users-and-move-to-webkit">they have announced</a> that future versions of the Opera browser will run on the WebKit rendering engine instead of their own Presto. Specifically, they will make use of the open-source Chromium browser, and include the V8 JavaScript engine.</p>
<h2>Opera Spills the Beans</h2>
<p>As means of early summary, Opera have written the following:</p>
<blockquote>
<p><strong>TL;DR</strong></p>
<ul>
<li>This will require no changes to your web development practices: <strong>keep coding to standards!</strong></li>
<li>Opera Extensions that you&#8217;ve built aren&#8217;t obsolete</li>
<li>Opera will contribute to the WebKit and Chromium projects</li>
<li>Our work on web standards to advance the web continues</li>
</ul>
</blockquote>
<p>These points indicate that this is largely an under-the-hood change, with little impact on routine coding. Functionally the browser will remain the same, extensions will continue as they have before. Opera are remaining in the browser game, and will have a hand in advancing the web as well as the WebKit and Chromium projects.</p>
<p>Opera&#8217;s rationale for the change is that while they built Presto at a time when the competition was sorely needed versus Internet Explorer and Netscape, it now makes less sense to duplicate efforts made on other modern engines (ie WebKit). It&#8217;s a reasonable rationale, but to me Opera having their own engine made them stand out as they could implement web standards at their own pace. This has been borne out in the past as they have often been ahead in certain areas. I even remember when Opera was the first browser to have native tabbed browsing, and Firefox at the time required a plugin!</p>
<p>A (quite) probable cause is the trend developers have been following in building styles specifically for WebKit browsers, making heavy use of the <code>-webkit-</code> prefix. This was <a href="http://www.netmagazine.com/news/opera-confirms-webkit-prefix-usage-121923">brought to the fore</a> last year by the kerfuffle around Opera announcing support for certain WebKit-prefixed CSS properties. Today&#8217;s news almost seems like a logical next step.</p>
<p>Up until now, the major rendering engine and browser landscape has been:</p>
<ul>
<li>Gecko &#8211; Firefox</li>
<li>Presto &#8211; Opera</li>
<li>Trident &#8211; Internet Explorer</li>
<li>Webkit &#8211; Safari, Chrome</li>
</ul>
<p>Given this change, the landscape becomes:</p>
<ul>
<li>Gecko &#8211; Firefox</li>
<li>Trident &#8211; Internet Explorer</li>
<li>Webkit &#8211; Safari, Chrome, Opera</li>
</ul>
<p>From what I can tell, this revelation has both positive and potentially negative ramifications.</p>
<p>It&#8217;s also been suggested that by switching to the &#8220;popular&#8221; engine, Opera may lose credibility in web standards development. I don&#8217;t see how &#8211; they are still Opera.</p>
<p>Peter-Paul Koch made <a href="http://www.quirksmode.org/blog/archives/2013/02/opera_switching.htm">the following remarks</a>:</p>
<blockquote>
<p>As many people remarked, we’re trading in a bit of diversity for an easier job as web developers. Opera-WebKit will likely be more similar to the other WebKit-based browsers, thus leading to less premature hair loss among developers. So far so good.</p>
<p>Still, there’s a dark lining to this silver cloud. [...]</p>
<p><em>The problem I’m having is “many of which have only been tested in WebKit browsers.” Note carefully what this means: we web developers haven’t been doing our jobs properly.</em> We didn’t bother to test our mobile sites on Opera Mini, even though it’s roughly as large as Safari iOS and Android.</p>
<p>I see this as a personal fail. I evidently haven’t been outspoken enough on the topic. I should have yelled in everybody’s ear until they did the proper thing.</p>
<p><em>It’s our own fault.</em></p>
</blockquote>
<p>Emphasis mine. The quote is revealing in how web developers have essentially forced this situation.</p>
<p>Jake Archibald, a Google employee, <a href="https://plus.google.com/116237864387312784020/posts/iRRPVaaPQvo">reflects on the announcement</a> and what it may mean for the web. Nice to see the pros and cons presented by someone who works for a competing company. John Resig even <a href="http://ejohn.org/blog/webkit-is-the-jquery-of-browser-engines/">likens WebKit to jQuery</a> with regard to its widespread use.</p>
<h2>The Positive</h2>
<p>Opera can contribute their knowledge and skills to the WebKit project, making it all the better. Hopefully things learned from maintaining Presto &#8211; such as <a href="http://caniuse.com/#search=forms">Opera&#8217;s advances in HTML5 form element support</a> &#8211; will make a positive impact.</p>
<p>Christian Heilmann <a href="http://christianheilmann.com/2013/02/13/i-will-miss-the-douglas-crockford-of-browsers/">touches on this</a> &#8211; he remarks:</p>
<blockquote>
<p>[...] I always called Opera the Douglas Crockford of browsers as it was ruthless in its implementation of standards. If something didn’t work in Opera there is a good chance that you did something wrong. Even better &#8211; fixing it in Opera in most cases meant looking at how the W3C standard meant things to work and write your code accordingly, which in most cases meant no change in other browsers, but cleaner code overall. Opera was my linting tool.</p>
</blockquote>
<p>This reflects the care Opera have taken in their implementation efforts. I suspect this would continue, regardless of the engine they use.</p>
<p>Recognizing that there is a difference between the browser and the rendering engine, this move means there will be one less engine to test for. Besides Internet Explorer, browsers tend to be updated on a regular basis, so I don&#8217;t imagine Presto-based installs will remain in wide use for long. Peter-Paul Koch <a href="http://www.quirksmode.org/blog/archives/2013/02/opera_switching.html">estimates</a> the first WebKit-powered Opera will appear this year, and that it will take a few years for Presto use to drop off entirely.</p>
<p>Generally, in my admittedly limited experience, Opera hasn&#8217;t been troublesome in standards support, so not much accommodation has been needed. Switching to WebKit will further level out browser differences. Nonetheless, while the <code>-o-</code> prefix in stylesheets will eventually become redundant, they should be kept around for the immediate future for backward compatibility. There aren&#8217;t <a href="http://www.opera.com/docs/specs/presto2.12/css/o-vendor/">very many</a>. Ultimately this will slightly reduce some development work.</p>
<h2>The Negative</h2>
<p>While Opera putting their weight behind WebKit can be a good thing, the resultant withdrawal of Presto will reduce diversity in the rendering engine landscape. It&#8217;s not to say that Opera (the browser) will become &#8220;yet another WebKit browser&#8221;, but that it may be less able to distinguish itself from the competition. In the past, Opera (the company) have been ahead in implementing various parts of web standards, notably HTML5 form elements. With the switch to WebKit, Opera&#8217;s pace may be tied to that of the WebKit project, for better or for worse. The flip side (also mentioned above) could be that web development and testing may be eased by greater consistency between browsers.</p>
<p>This leads to a concern that the web browser landscape may be moving toward a WebKit monoculture. Sure, there&#8217;s still Internet Explorer and Firefox with their distinct engines, but WebKit is a big player on mobile devices, and growing on desktop/laptop systems. This can be good or bad; it&#8217;s to early too tell, but it worries me slightly. Competition is a good thing, and removing a player (Presto, in this case) can adversely affect the landscape, and possibly make the other players (the other engines) complacent. Which is kind of veering towards where the browser market was in the early days of Internet Explorer 6.</p>
<p>Returning to the prefixes issue, given the Opera will be using WebKit I have to wonder how browser-specific CSS can be issued. There will be multiple browsers supporting WebKit, yet each browser may use a different version, and likely support different features (as Safari and Chrome have done, I believe). Could styles still be written to target specific browsers, or does using WebKit simply lump them all together?</p>
<h2>Time will be the Judge</h2>
<p>It&#8217;s much too early to know how this will turn out. Here and now, I&#8217;m very mixed. In past years Opera has been a unique browser, with it&#8217;s own engine and features, with better standards support in some regards. By switching from Presto to WebKit, there is some perception in the community that Opera will become &#8220;yet another WebKit browser&#8221;. I don&#8217;t necessarily agree with that sentiment. I&#8217;ve no doubt the Opera team considered this long and hard prior to the announcement, so they may well believe this is the best step forward.</p>
<h2>Additional Reading</h2>
<p>I&#8217;ve been reading a number of other developers sharing their thoughts on this change. Below I&#8217;ve linked to a number of very interesting views.</p>
<ul>
<li><a href="http://christianheilmann.com/2013/02/13/i-will-miss-the-douglas-crockford-of-browsers/">I will miss the &#8220;Douglas Crockford of browsers”</a> (Christian Heilmann)</li>
<li><a href="http://www.quirksmode.org/blog/archives/2013/02/opera_switching.html">Opera switching to WebKit: thoughts and guesses</a> (Peter-Paul Koch)</li>
<li><a href="http://ejohn.org/blog/webkit-is-the-jquery-of-browser-engines/">WebKit is the jQuery of Browser Engines</a> (John Resig)</li>
<li><a href="http://meyerweb.com/eric/thoughts/2013/02/13/presto-change-o/">Presto Change-o</a> (Eric Meyer)</li>
<li><a href="http://robertnyman.com/2013/02/13/the-webkit-culture-web-rendering-engine-diversity/">The WebKit Culture &amp; Web Rendering Engine Diversity</a> (Robert Nyman)</li>
<li><a href="http://www.netmagazine.com/news/devs-respond-opera-webkit-switch-132567">Devs respond to Opera WebKit switch</a> (.net Magazine)</li>
<li><a href="http://www.brucelawson.co.uk/2013/opera-and-webkit-a-personal-perspective/">Opera and WebKit: a personal perspective</a> (Bruce Lawson)</li>
</ul>
<p>The post <a href="http://grantpalin.com/2013/02/13/opera-to-leave-presto-go-to-webkit/">Opera to leave Presto, go to Webkit</a> appeared first on <a href="http://grantpalin.com">GrantPalin.com</a>.</p><img src="http://feeds.feedburner.com/~r/grantpalin/~4/TBhmgluasCA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://grantpalin.com/2013/02/13/opera-to-leave-presto-go-to-webkit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Theming – Partial Templates with get_template_part()</title>
		<link>http://grantpalin.com/2013/02/12/wordpress-theming-partial-templates-with-get_template_part/</link>
		<comments>http://grantpalin.com/2013/02/12/wordpress-theming-partial-templates-with-get_template_part/#comments</comments>
		<pubDate>Wed, 13 Feb 2013 06:01:03 +0000</pubDate>
		<dc:creator>Grant</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://grantpalin.com/?p=2526</guid>
		<description><![CDATA[<p>WordPress provides numerous functions to aid theme developers in building themes. This post features one function in particular: get_template_part().</p><p>The post <a href="http://grantpalin.com/2013/02/12/wordpress-theming-partial-templates-with-get_template_part/">WordPress Theming &#8211; Partial Templates with get_template_part()</a> appeared first on <a href="http://grantpalin.com">GrantPalin.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<h2>Introduction</h2>
<p>It used to be that WordPress theme templates were monolithic beasts, with a fair bit of looping and conditional logic to display content in a certain way. I know, I&#8217;ve done it too. In past years, this has been helped somewhat with the availability of content-type-specific template files, such as page.php, attachment.php, and so on. This helped to reduce the monolithic aspect of, say, index.php and single.php. However, the result was repeated code across multiple files (almost even a <em>multitude</em>). Repeated and redundant code should make any coder cringe. Well, there is a further step to take with the use of a little function called get&#95;template&#95;part().</p>
<h2>Introducing <code>get_template_part()</code></h2>
<p><code>get_template_part()</code> was <a href="http://codex.wordpress.org/Version_3.0">introduced in WordPress 3.0</a>, and is a more general form of existing functions used to pull in template code from another file (such as header, footer, and sidebar). Indeed, it is now possible to have common code in one file, and use the function to include template code pertinent to a particular content type. The specific files could be termed <strong>partials</strong>, or <strong>fragments</strong>.</p>
<p>The function signature looks like this:</p>
<p><code>get_template_part({general}, {specific});</code></p>
<p>The first parameter is required, while the second is optional. If both parameters are used, the function attempts to include a file with the following name:</p>
<p><code>{general}-{specific}.php</code></p>
<p>If the <code>{specific}</code> parameter is not given, or if it is given and the resulting combination filename does not exist, the function will try to include the <code>{general}.php</code> file. If the <code>{general}.php</code> file does not exist, no file is included. In any situation where the expected partial file does not exist, the general fallback is tried, and if that does not exist, the function ends without errors.</p>
<p>To reiterate, the function behaviour works as follows, stopping with the first action that succeeds:</p>
<ol>
<li>Include <code>{general}-{specific}.php</code></li>
<li>Include <code>{general}.php</code></li>
<li>Exit without error</li>
</ol>
<p>Another advantage is that the inclusion is always done relative to the theme&#8217;s directory, so there is no need to worry about file paths.</p>
<p>This function seems simple, yet when used appropriately can be used to break down theme templates into reusable modules, reducing redundant code and the need for large logic blocks.</p>
<p><code>get_template_part()</code> is a generalization, is intended to be used for consuming template partials, and is not suitable where existing specialty functions already exist, such as <code>get_header()</code>, <code>get_footer()</code>, and <code>get_sidebar()</code>.</p>
<h2>An Example Implementation</h2>
<p>A common task in theming is looping through content to present a list of e.g. posts or pages. These are often done in different contexts, including author, tag, category, and date archives as well as the index template. Regardless of context, the main loop is usually done similar to the following:</p>
<pre><code>&lt;?php
if (have_posts()):
    while (have_posts()):
        the_post();
?&gt;
&lt;!-- template markup goes here --&gt;
&lt;?php
    endwhile;
else: // no posts found
?&gt;
&lt;p&gt;No posts found matching your criteria.&lt;/p&gt;
&lt;?php
endif; // done checking for posts
?&gt;
</code></pre>
<p>It&#8217;s not a long block of code, but it would have to be repeated in at least the contexts mentioned above. If the output markup was to be kept the same in these contexts, and a change was introduced in one context, the same change would need to be introduced in the other locations as well. That&#8217;s just cringe-inducing.</p>
<p>Suppose that this common loop code could be extracted into a fragment, <code>loop.php</code>. In each of the contexts listed above, the common looping code could be replaced with:</p>
<p><code>get_template_part('loop');</code></p>
<p>The code block above, based in <code>loop.php</code>, would be dynamically loaded into the current context, executed, and output the resulting markup. This is all well and good if the generated markup is intended to be the same in each context. But if not, then this is an opportunity for <code>get_template_part()</code> to shine.</p>
<p>If a certain context, say the author archive, requires different markup output compared to the other contexts, a specialized loop fragment can be introduced as <code>loop-author.php</code>. Perhaps the other contexts have a common way of showing posts, with thumbnails and metadata, but the author archive is preferred to just have a list of text links to the author&#8217;s posts. That&#8217;s where <code>loop-author.php</code> would come in; the overall loop would remain the same, but the markup can be changed. The author archive template file can then use the specialized fragment with the following code:</p>
<p><code>get_template_part('loop', 'author');</code></p>
<p>The resulting filename would be <code>loop-author.php</code>, and the matching file will be loaded and executed. The contents of <code>loop-author.php</code> could look like the following:</p>
<pre><code>&lt;?php
if (have_posts()):
?&gt;
&lt;ul&gt;
&lt;?php
    while (have_posts()):
        the_post();
?&gt;
    &lt;li&gt;&lt;a href="&lt;?php the_permalink() ?&gt;"&gt;&lt;?php the_title() ?&gt;&lt;/a&gt;&lt;/li&gt;
&lt;?php
    endwhile;
?&gt;
&lt;/ul&gt;
&lt;?php
else: // no posts found
?&gt;
&lt;p&gt;No posts found matching your criteria.&lt;/p&gt;
&lt;?php
endif; // done checking for posts
?&gt;
</code></pre>
<p>Yes, it&#8217;s simplistic, but the point is that the posts listing can be generated differently for the author archive versus the other archive types. The output will resemble the following image:</p>
<div class="image large">
  <img src="http://grantpalin.com/wp-content/uploads/2013/02/author-archive-posts-listing.png" alt="Author archive posts listing, using an author template file" class="size-full wp-image-2532" />Output of simple get_template_part() implementation.
</div>
<p>Following from this, it would be possible to have different loop outputs for each of these contexts, retaining the generic <code>loop.php</code> for cases where no special customization is needed. Whether that would be needed is another matter, but the point is that the use of this technique allows coders to compartmentalize theme components with minimal extra work.</p>
<h2>Conclusion</h2>
<p>I didn&#8217;t learn about <code>get_template_part()</code> until several months ago, even though it has been in WordPress for some time. Once I understood it, however, I quickly realized the ways it can be used to componentize themes and template files, noticeably reducing repeated code yet allowing for customizing output in different contexts. All without requiring large blocks of logic code to determine what to display. This function can be a workhorse, and should be a part of any theme developer&#8217;s toolbox.</p>
<h2>Additional Reading</h2>
<ul>
<li><a href="http://codex.wordpress.org/Function_Reference/get_template_part">get&#95;template&#95;part (WordPress Codex)</a></li>
<li><a href="http://kovshenin.com/2013/get_template_part/">Understanding get&#95;template&#95;part (Konstantin Kovshenin)</a></li>
<li><a href="http://waterstreetgm.org/tighter-and-leaner-wordpress-templates-with-get_template_part/">Tighter and leaner WordPress templates with get&#95;template&#95;part() (Terry Sutton)</a></li>
</ul>
<p>The post <a href="http://grantpalin.com/2013/02/12/wordpress-theming-partial-templates-with-get_template_part/">WordPress Theming &#8211; Partial Templates with get_template_part()</a> appeared first on <a href="http://grantpalin.com">GrantPalin.com</a>.</p><img src="http://feeds.feedburner.com/~r/grantpalin/~4/YxWKAMolwBA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://grantpalin.com/2013/02/12/wordpress-theming-partial-templates-with-get_template_part/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Web Performance 101: An opinionated guide to the 22 links every developer should read</title>
		<link>http://grantpalin.com/2013/02/07/web-performance-101-an-opinionated-guide-to-the-22-links-every-developer-should-read/</link>
		<comments>http://grantpalin.com/2013/02/07/web-performance-101-an-opinionated-guide-to-the-22-links-every-developer-should-read/#comments</comments>
		<pubDate>Fri, 08 Feb 2013 07:18:51 +0000</pubDate>
		<dc:creator>Grant</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://grantpalin.com/?p=2522</guid>
		<description><![CDATA[<p>A splendid roundup of articles and posts on how to maximize webpage and application performance. The entries are divided into multiple categories, including the basics, images, security, scripting, and tooling. There&#8217;s much good reading to be had here.</p><p>The post <a href="http://grantpalin.com/2013/02/07/web-performance-101-an-opinionated-guide-to-the-22-links-every-developer-should-read/">Web Performance 101: An opinionated guide to the 22 links every developer should read</a> appeared first on <a href="http://grantpalin.com">GrantPalin.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>A splendid roundup of articles and posts on how to maximize webpage and application performance. The entries are divided into multiple categories, including the basics, images, security, scripting, and tooling. There&#8217;s much good reading to be had here.</p>
<p>The post <a href="http://grantpalin.com/2013/02/07/web-performance-101-an-opinionated-guide-to-the-22-links-every-developer-should-read/">Web Performance 101: An opinionated guide to the 22 links every developer should read</a> appeared first on <a href="http://grantpalin.com">GrantPalin.com</a>.</p><img src="http://feeds.feedburner.com/~r/grantpalin/~4/x3LGmTRrWQI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://grantpalin.com/2013/02/07/web-performance-101-an-opinionated-guide-to-the-22-links-every-developer-should-read/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss><!-- Dynamic page generated in 0.583 seconds. --><!-- Cached page generated by WP-Super-Cache on 2013-05-16 16:25:27 --><!-- Compression = gzip -->
