<?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>Konstruktors &#187; code</title>
	<atom:link href="http://konstruktors.com/blog/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://konstruktors.com</link>
	<description>Web Design, WordPress and Performance Services</description>
	<lastBuildDate>Sat, 19 May 2012 16:41:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-beta4-20805</generator>
<atom:link rel="hub" href="http://konstruktors.superfeedr.com/"/><atom:link rel="hub" href="http://pubsubhubbub.appspot.com/"/>		<item>
		<title>Enable WordPress Dashboard Quick&#160;Login</title>
		<link>http://konstruktors.com/blog/wordpress/3594-wordpress-dashboard-quick-login/</link>
		<comments>http://konstruktors.com/blog/wordpress/3594-wordpress-dashboard-quick-login/#comments</comments>
		<pubDate>Sun, 26 Feb 2012 19:30:00 +0000</pubDate>
		<dc:creator>Kaspars</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://konstruktors.com/?p=3594</guid>
		<description><![CDATA[All of the web browsers today have input autocomplete or auto-fill feature built-in and chances are that you have your WordPress username and password stored in the browser and the input fields are completed automatically upon visiting /wp-login.php. Wouldn&#8217;t it be nice if WordPress would log you in automatically if the fields have been pre-filled [...]]]></description>
			<content:encoded><![CDATA[<p>All of the web browsers today have input autocomplete or auto-fill feature built-in and chances are that you have your WordPress username and password stored in the browser and the input fields are completed automatically upon visiting <code>/wp-login.php</code>. Wouldn&#8217;t it be nice if WordPress would log you in <strong>automatically</strong> if the fields have been pre-filled by the browser?</p>
<p><iframe src="http://www.screenr.com/embed/iLT8" frameborder="0" width="500" height="305"></iframe></p>
<p>Here is a simple snippet of PHP and Javascript that checks if the input fields have been filled and submits the login form one second after the page has been loaded. All you have to do is append <code>#quicklogin</code> to your login bookmark URL so that it looks like <code>http://example.com/wp-admin/#quicklogin</code> and Javascript will do its magic. Add this to your <code>functions.php</code>.</p>
<pre>add_action('login_footer', 'enable_admin_quick_login');
function enable_admin_quick_login() {
?&gt;
	&lt;script type="text/javascript"&gt;
		$url_hash = window.location.hash;
		if ($url_hash.indexOf('quicklogin') != -1) {
			setTimeout(function() {
				if (document.loginform.user_login.value &amp;&amp; document.loginform.user_pass.value) {
					document.loginform.submit();
				}
			}, 1000);
		}
	&lt;/script&gt;
&lt;?php
}</pre>
<h4>Related posts</h4><ol>
<li><a href='http://konstruktors.com/blog/wordpress/3529-custom-redirect-to-wordpress-login-dashboard/' rel='bookmark' title='Add Custom URL Redirects to Your WordPress Dashboard Areas or Login&nbsp;Page'>Add Custom URL Redirects to Your WordPress Dashboard Areas or Login&nbsp;Page</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/3203-how-to-automatically-add-image-credit-or-source-url-to-photo-captions-in-wordpress/' rel='bookmark' title='How to Automatically Add Image Credit or Source URL to Photo Captions in&nbsp;WordPress'>How to Automatically Add Image Credit or Source URL to Photo Captions in&nbsp;WordPress</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/2885-enable-plugin-theme-updates-and-pretty-permalinks-nginx/' rel='bookmark' title='Enable WordPress Plugin, Theme Updates and Pretty Permalinks on&nbsp;Nginx'>Enable WordPress Plugin, Theme Updates and Pretty Permalinks on&nbsp;Nginx</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://konstruktors.com/blog/wordpress/3594-wordpress-dashboard-quick-login/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Avoid Widow &#8220;Read More&#8221; Links in Post&#160;Excerpts</title>
		<link>http://konstruktors.com/blog/wordpress/3462-avoid-widow-read-more-links/</link>
		<comments>http://konstruktors.com/blog/wordpress/3462-avoid-widow-read-more-links/#comments</comments>
		<pubDate>Wed, 22 Feb 2012 09:30:34 +0000</pubDate>
		<dc:creator>Kaspars</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[action]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://konstruktors.com/?p=3462</guid>
		<description><![CDATA[A &#8220;widow&#8221; in typography is defined as: A paragraph-ending line that falls at the beginning of the following page/column, thus separated from the rest of the text. If you are using the standard inline &#8220;Read more&#8221; links at the end of post excerpts on index and archive pages, here is a simple filter to ensure [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://konstruktors.com/wp-content/uploads/2012/02/read-more-widow-last-word-wordpress.jpg"><img class="aligncenter size-medium wp-image-3549" title="Read more link widow in WordPress excerpts" src="http://konstruktors.com/wp-content/uploads/2012/02/read-more-widow-last-word-wordpress-500x150.jpg" alt="Read more link widow in WordPress excerpts" width="500" height="150" /></a></p>
<p>A &#8220;widow&#8221; in typography is defined as:</p>
<blockquote><p>A paragraph-ending line that falls at the beginning of the following page/column, thus separated from the rest of the text.</p></blockquote>
<p>If you are using the standard inline &#8220;Read more&#8221; links at the end of post excerpts on index and archive pages, here is a simple filter to ensure that a non-breaking space is added before the &#8220;Read more&#8221; link:</p>
<pre>add_filter('the_content_more_link', 'prepend_non_breaking');
function prepend_non_breaking($more_link) {
	return str_replace(' &lt;a ', '&amp;nbsp;&lt;a ', $more_link);
}</pre>
<h4>Related posts</h4><ol>
<li><a href='http://konstruktors.com/blog/wordpress/3364-sticky-posts-as-category-description/' rel='bookmark' title='Use Sticky Posts as Category&nbsp;Description'>Use Sticky Posts as Category&nbsp;Description</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/944-widget-context-update-word-count-check/' rel='bookmark' title='Widget Context Update &#8212; Word Count&nbsp;Check'>Widget Context Update &#8212; Word Count&nbsp;Check</a></li>
<li><a href='http://konstruktors.com/blog/media-publishing/873-rights-to-read-a-book-out-loud/' rel='bookmark' title='Rights to Read a Book Out&nbsp;Loud'>Rights to Read a Book Out&nbsp;Loud</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://konstruktors.com/blog/wordpress/3462-avoid-widow-read-more-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add Custom URL Redirects to Your WordPress Dashboard Areas or Login&#160;Page</title>
		<link>http://konstruktors.com/blog/wordpress/3529-custom-redirect-to-wordpress-login-dashboard/</link>
		<comments>http://konstruktors.com/blog/wordpress/3529-custom-redirect-to-wordpress-login-dashboard/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 10:00:30 +0000</pubDate>
		<dc:creator>Kaspars</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://konstruktors.com/?p=3529</guid>
		<description><![CDATA[Ever wanted to use something like example.com/backend or example.com/dash to access your WordPress dashboard or login area? Here is a simple snippet of PHP for your functionality plugin or functions.php to do just that &#8212; it uses standard WordPress URL rewrite API. Update: turns out that in WordPress 3.4 there are new default redirects (/admin, [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wanted to use something like <code>example.com/backend</code> or <code>example.com/dash</code> to access your WordPress dashboard or login area? <del>Here is a simple snippet of PHP for your <em>functionality</em> plugin or <code>functions.php</code> to do just that &#8212; it uses standard WordPress URL rewrite API.</del></p>
<p><strong>Update:</strong> turns out that in WordPress 3.4 there are new default redirects (<code>/admin</code>, <code>/dashboard</code> and <code>/login</code>) implemented in the core (see <a href="http://core.trac.wordpress.org/changeset/19880">this ticket</a>). So here is a better way to add your own redirects which will work only if you don&#8217;t have a page or post with the same name (slug) already:</p>
<h3>Updated Version:</h3>
<pre>add_action('template_redirect', 'add_my_custom_redirects');
function add_my_custom_redirects() {
	if (!is_404())
		return;
	$current_uri = untrailingslashit($_SERVER['REQUEST_URI']);
	$my_admin_uris = array(
		home_url('dash', 'relative'),
		home_url('your-custom-uri', 'relative')
	);
	if (in_array($current_uri, $my_admin_uris)) {
 		wp_redirect(admin_url());
 		exit;
	}
}</pre>
<h3>The Obsolete Version:</h3>
<pre>add_filter('generate_rewrite_rules', 'add_my_custom_rewrites');
function add_my_custom_rewrites($wp_rewrite) {
    $my_rewrites = array(
	'dash' =&gt; 'wp-admin'
    );
    $wp_rewrite-&gt;rules = $my_rewrites + $wp_rewrite-&gt;rules;
}</pre>
<h4>Related posts</h4><ol>
<li><a href='http://konstruktors.com/blog/wordpress/3594-wordpress-dashboard-quick-login/' rel='bookmark' title='Enable WordPress Dashboard Quick&nbsp;Login'>Enable WordPress Dashboard Quick&nbsp;Login</a></li>
<li><a href='http://konstruktors.com/blog/web-design/570-wordpress-dashboard-ui-idea-3/' rel='bookmark' title='WordPress Dashboard UI Idea&nbsp;#3'>WordPress Dashboard UI Idea&nbsp;#3</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/270-baltic-amber-1-32-removed-youhave-from-dashboard/' rel='bookmark' title='Baltic Amber 1.32 &#8212; removed .youare section from your WordPress&nbsp;Dashboard'>Baltic Amber 1.32 &#8212; removed .youare section from your WordPress&nbsp;Dashboard</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://konstruktors.com/blog/wordpress/3529-custom-redirect-to-wordpress-login-dashboard/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>How to Remove All Line Breaks from Text Using&#160;Regex</title>
		<link>http://konstruktors.com/blog/web-design/3517-regex-remove-all-line-breaks-from-text/</link>
		<comments>http://konstruktors.com/blog/web-design/3517-regex-remove-all-line-breaks-from-text/#comments</comments>
		<pubDate>Sat, 18 Feb 2012 10:45:27 +0000</pubDate>
		<dc:creator>Kaspars</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://konstruktors.com/?p=3517</guid>
		<description><![CDATA[If you are generating &#60;meta&#62; description tags automatically (e.g. by including all headings of the document), chances are that you&#8217;re extracting it from various sources of content that contain different HTML elements and line breaks in them. Here is a simple regular expression to remove all line breaks, carriage returns and tabs, and replace them with an [...]]]></description>
			<content:encoded><![CDATA[<p>If you are generating <code>&lt;meta&gt;</code> <em>description</em> tags automatically (e.g. by <a title="Extract headings and headlines from HTML documents" href="http://konstruktors.com/blog/web-design/3507-regex-extract-headings-h1-h2-h3-from-html/">including all headings of the document</a>), chances are that you&#8217;re extracting it from various sources of content that contain different HTML elements and line breaks in them. Here is a simple regular expression to <strong>remove all line breaks, carriage returns and tabs</strong>, and replace them with an empty space.</p>
<pre>$text = preg_replace("/\r\n+|\r+|\n+|\t+/i", " ", $text);</pre>
<h4>Related posts</h4><ol>
<li><a href='http://konstruktors.com/blog/wordpress/2920-remove-inline-css-line-breaks-galleries/' rel='bookmark' title='Remove Inline CSS and Line Breaks in WordPress&nbsp;Galleries'>Remove Inline CSS and Line Breaks in WordPress&nbsp;Galleries</a></li>
<li><a href='http://konstruktors.com/blog/web-design/3507-regex-extract-headings-h1-h2-h3-from-html/' rel='bookmark' title='How to Extract Heading Content (H1, H2, etc.) from an HTML String Using&nbsp;Regex'>How to Extract Heading Content (H1, H2, etc.) from an HTML String Using&nbsp;Regex</a></li>
<li><a href='http://konstruktors.com/blog/random-musings/191-simple-fullscreen-text-editors-for-students-bloggers-writers/' rel='bookmark' title='Simple Fullscreen Text Editors for Students, Bloggers, Journalists and&nbsp;Writers'>Simple Fullscreen Text Editors for Students, Bloggers, Journalists and&nbsp;Writers</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://konstruktors.com/blog/web-design/3517-regex-remove-all-line-breaks-from-text/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Extract Heading Content (H1, H2, etc.) from an HTML String Using&#160;Regex</title>
		<link>http://konstruktors.com/blog/web-design/3507-regex-extract-headings-h1-h2-h3-from-html/</link>
		<comments>http://konstruktors.com/blog/web-design/3507-regex-extract-headings-h1-h2-h3-from-html/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 10:10:49 +0000</pubDate>
		<dc:creator>Kaspars</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://konstruktors.com/?p=3507</guid>
		<description><![CDATA[Headlines and headings are usually very relevant and descriptive pieces of information for any HTML page. You might want to include them into the description &#60;meta&#62; tag on that page. Here is a simple regular expression to extract all those headings: preg_match_all('&#124;&#60;h[^&#62;]+&#62;(.*)&#60;/h[^&#62;]+&#62;&#124;iU', $html, $headings); Related posts Logos and Names Are Not&#160;Headings How to Create Beautiful [...]]]></description>
			<content:encoded><![CDATA[<p>Headlines and headings are usually very relevant and descriptive pieces of information for any HTML page. You might want to include them into the <em>description</em> <code>&lt;meta&gt;</code> tag on that page. Here is a simple regular expression to extract all those headings:</p>
<pre>preg_match_all('|&lt;h[^&gt;]+&gt;(.*)&lt;/h[^&gt;]+&gt;|iU', $html, $headings);</pre>
<h4>Related posts</h4><ol>
<li><a href='http://konstruktors.com/blog/web-design/31-logos-names-are-not-h1-headings/' rel='bookmark' title='Logos and Names Are Not&nbsp;Headings'>Logos and Names Are Not&nbsp;Headings</a></li>
<li><a href='http://konstruktors.com/blog/web-design/125-how-to-create-beautiful-and-elegant-html-lists-using-css/' rel='bookmark' title='How to Create Beautiful and Elegant HTML Lists Using&nbsp;CSS'>How to Create Beautiful and Elegant HTML Lists Using&nbsp;CSS</a></li>
<li><a href='http://konstruktors.com/blog/web-design/2036-remove-index-html-from-the-url/' rel='bookmark' title='Remove index.html from the&nbsp;URL'>Remove index.html from the&nbsp;URL</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://konstruktors.com/blog/web-design/3507-regex-extract-headings-h1-h2-h3-from-html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Add Post Categories and Tags as #Hashtags to Tweets Automatically with the Simple Twitter Connect&#160;Plugin</title>
		<link>http://konstruktors.com/blog/wordpress/3478-add-post-categories-tags-as-hashtags-to-tweets-automatically-stc-plugin/</link>
		<comments>http://konstruktors.com/blog/wordpress/3478-add-post-categories-tags-as-hashtags-to-tweets-automatically-stc-plugin/#comments</comments>
		<pubDate>Wed, 15 Feb 2012 00:16:03 +0000</pubDate>
		<dc:creator>Kaspars</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://konstruktors.com/?p=3478</guid>
		<description><![CDATA[Simple Twitter Connect is a really useful, simple and well coded plugin by Otto (@Otto42) that allows you to post tweets right from your WordPress dashboard or automatically after publishing new posts. A standard tweet containing a prefix (such as &#8220;New blog post:&#8221;), post title and a link to that post is generated automatically by the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://ottopress.com/wordpress-plugins/simple-twitter-connect/">Simple Twitter Connect</a> is a really useful, simple and well coded plugin by <a href="http://ottopress.com/">Otto</a> (<a href="https://twitter.com/#!/Otto42">@Otto42</a>) that allows you to post tweets right from your WordPress dashboard or automatically after publishing new posts.</p>
<p>A standard tweet containing a prefix (such as &#8220;New blog post:&#8221;), post title and a link to that post is generated automatically by the plugin. Wouldn&#8217;t it be nice to include also <strong>post categories and tags as hashtags</strong> in order to add additional metadata along with the post title? Like so:</p>
<div id="attachment_3483" class="wp-caption aligncenter" style="width: 510px"><a href="http://konstruktors.com/wp-content/uploads/2012/02/twitter-publisher-before-after.jpg"><img class="size-medium wp-image-3483" title="Post categories and tags added as hashtags in Twitter Publisher using Simple Twitter Connect plugin" src="http://konstruktors.com/wp-content/uploads/2012/02/twitter-publisher-before-after-500x292.jpg" alt="Post categories and tags added as hashtags in Twitter Publisher using Simple Twitter Connect plugin" width="500" height="292" /></a><p class="wp-caption-text">Post categories and tags replaced or added to tweet as hashtags</p></div>
<p>Thanks to the <code>stc_publish_text</code> filter supplied with the plugin there is an easy way to do it. Add this snippet to your theme&#8217;s <code>functions.php</code>:</p>
<pre>add_filter('stc_publish_text', 'add_taxonomies_to_tweets', 10, 2);
function add_taxonomies_to_tweets($output, $id) {
	if ($cats = get_the_category($id))
		foreach ($cats as $c =&gt; $cat)
			$output = add_taxonomy_hashtag($output, $cat-&gt;cat_name);
	if ($tags = get_the_tags($id))
		foreach ($tags as $t =&gt; $tag)
			$output = add_taxonomy_hashtag($output, $tag-&gt;name);
	return $output;
}
function add_taxonomy_hashtag($tweet, $tax) {
	if (stripos($tax, ' ')) // Remove whitespace
		$tax = str_replace(' ', '', $tax);
	if (strlen($tweet) + 1 &gt; 140) { // Check if the new tweet is not too long
		return $tweet;
	} elseif (stripos($tweet, $tax)) {  // Replace an existing word with a tag
		return str_replace($tax, '#' . $tax, $tweet);
	} elseif (strlen($tweet) + strlen($tax) + 1 &lt; 140) { // or simply append it
		return $tweet . ' #' . $tax;
	}
	return $tweet;
}</pre>
<h4>Related posts</h4><ol>
<li><a href='http://konstruktors.com/blog/wordpress/3203-how-to-automatically-add-image-credit-or-source-url-to-photo-captions-in-wordpress/' rel='bookmark' title='How to Automatically Add Image Credit or Source URL to Photo Captions in&nbsp;WordPress'>How to Automatically Add Image Credit or Source URL to Photo Captions in&nbsp;WordPress</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/1850-automatically-escape-html-entities-of-code-fragments-in-comments/' rel='bookmark' title='Automatically Escape HTML Entities of Code Fragments in&nbsp;Comments'>Automatically Escape HTML Entities of Code Fragments in&nbsp;Comments</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/2667-how-to-add-shortlink-support-to-twitter-tools/' rel='bookmark' title='How to Add Shortlink Support to Twitter&nbsp;Tools'>How to Add Shortlink Support to Twitter&nbsp;Tools</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://konstruktors.com/blog/wordpress/3478-add-post-categories-tags-as-hashtags-to-tweets-automatically-stc-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML5 Notepad App&#160;Update</title>
		<link>http://konstruktors.com/blog/web-design/3451-html5-notepad-app-update/</link>
		<comments>http://konstruktors.com/blog/web-design/3451-html5-notepad-app-update/#comments</comments>
		<pubDate>Sun, 12 Feb 2012 03:21:13 +0000</pubDate>
		<dc:creator>Kaspars</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[offline]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://konstruktors.com/?p=3451</guid>
		<description><![CDATA[I have released an updated version of my HTML5 Notepad app which features a new user interface, adds support for Markdown syntax (along with a simple editor and preview) and fixes a synchronization bug which in some cases converted line breaks into text. Please note that there could still be some bugs and the code hasn&#8217;t been polished for [...]]]></description>
			<content:encoded><![CDATA[<p>I have released an updated version of my <a title="HTML5 Notepad app with sync, markdown and offline access" href="http://konstruktors.com/projects/html5-notepad/">HTML5 Notepad app</a> which features a new user interface, adds support for Markdown syntax (along with a simple editor and preview) and fixes a synchronization bug which in some cases converted line breaks into text.</p>
<p><a href="http://konstruktors.com/projects/html5-notepad/"><img class="aligncenter size-medium wp-image-3438" title="HTML5 Notepad with Markdown syntax and sync support" src="http://konstruktors.com/wp-content/uploads/2011/05/html5-notepad-2012-editor-markdown-500x316.png" alt="HTML5 Notepad with Markdown syntax and sync support" width="500" height="316" /></a></p>
<p>Please note that there could still be some bugs and the code hasn&#8217;t been polished for a production use, but it serves as a very useful example of some of the most interesting HTML5 features such as localStorage and offline cache.</p>
<p>You can fork it on <a title="HTML5 notepad app with offline storage and sync" href="https://github.com/kasparsd/HTML5-Notepad-with-Sync">GitHub</a> or download from the <a title="HTML5 Notepad app with offline access, synchronization and Markdown syntax" href="http://konstruktors.com/projects/html5-notepad/">project page</a>.</p>
<h4>Related posts</h4><ol>
<li><a href='http://konstruktors.com/blog/the-web/2991-hosted-html5-notepad-app-sync/' rel='bookmark' title='Self-hosted HTML5 Notepad App With&nbsp;Synchronization'>Self-hosted HTML5 Notepad App With&nbsp;Synchronization</a></li>
<li><a href='http://konstruktors.com/blog/web-design/91-got-ie8-meta-tag-in-head-html5-doctype-progress/' rel='bookmark' title='Got a meta in a heada&#8217; — supporting standards and welcoming IEn where n =&nbsp;1…∞'>Got a meta in a heada&#8217; — supporting standards and welcoming IEn where n =&nbsp;1…∞</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://konstruktors.com/blog/web-design/3451-html5-notepad-app-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use Sticky Posts as Category&#160;Description</title>
		<link>http://konstruktors.com/blog/wordpress/3364-sticky-posts-as-category-description/</link>
		<comments>http://konstruktors.com/blog/wordpress/3364-sticky-posts-as-category-description/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 14:24:56 +0000</pubDate>
		<dc:creator>Kaspars</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://konstruktors.com/?p=3364</guid>
		<description><![CDATA[On putukrejums.lv blog we use the &#8216;sticky&#8217; posts to add introductory information to all category pages (see here, for example). This approach is better than using the category description field because it allows for all the usual formatting options. Here is how to add sticky posts on top of their respective category index pages and hide them [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://konstruktors.com/wp-content/uploads/2011/11/putukrejums-sticky-posts-category-introduction.jpg"><img class="alignnone size-medium wp-image-3369" title="Sticky posts as Category Description" src="http://konstruktors.com/wp-content/uploads/2011/11/putukrejums-sticky-posts-category-introduction-500x330.jpg" alt="Sticky posts as Category Description" width="500" height="330" /></a></p>
<p>On <a href="http://putukrejums.lv">putukrejums.lv</a> blog we use the &#8216;sticky&#8217; posts to add introductory information to all category pages (<a href="http://putukrejums.lv/tavas-kazas/">see here</a>, for example). This approach is better than using the category description field because it allows for all the usual formatting options.<span id="more-3364"></span></p>
<p>Here is how to add sticky posts on top of their respective category index pages and hide them from the rest of pages and indexes:</p>
<pre>add_action('pre_get_posts', 'alter_stickies');
function alter_stickies($query) {
	if (!$query-&gt;is_category &amp;&amp; !$query-&gt;is_single)
		$query-&gt;set('post__not_in', get_option('sticky_posts'));
}
add_filter('posts_orderby', 'sticky_orderby');
function sticky_orderby($orderby){
	global $wpdb;
	if (is_category())
		$orderby = "Field(". $wpdb-&gt;prefix ."posts.ID," . implode(',', get_option('sticky_posts')) . ") DESC, " . $orderby;
 	return $orderby;
}</pre>
<p>Add the <code>is-sticky</code> class to the post wrap for additional formatting control:</p>
<pre>add_filter('post_class', 'add_stickies_class');
function add_stickies_class($classes) {
	if (is_sticky())
		$classes[] = 'is-sticky';
	return $classes;
}</pre>
<h3>Redirect Sticky Posts to Their Category Index Page</h3>
<p>We don&#8217;t want the sticky posts to be available as individual posts that can be access via their permalinks because this information is already being displayed at the top of every category index page. Here is a simple filter to redirect all sticky posts to their category index pages:</p>
<pre>add_action('template_redirect', 'redirect_stickies');
function redirect_stickies() {
	global $wp_query;
	if (!is_single())
		return;
	$stickies = get_option('sticky_posts');
	if (empty($stickies))
		return;
 	if (in_array($wp_query-&gt;post-&gt;ID, $stickies))
		if ($cats = get_the_category($wp_query-&gt;post-&gt;ID))
			if ($cat = end($cats))
				wp_redirect(get_category_link($cat-&gt;cat_ID), '302');
}</pre>
<h4>Related posts</h4><ol>
<li><a href='http://konstruktors.com/blog/wordpress/3177-exclude-sticky-posts-from-adjacent-post-links/' rel='bookmark' title='How to Exclude Sticky Posts from Adjacent Post&nbsp;Links'>How to Exclude Sticky Posts from Adjacent Post&nbsp;Links</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/3335-remove-view-all-posts-filed-under-category-widget/' rel='bookmark' title='How to Remove &#8220;View all posts filed under&#8221; Prefix from Link Title Attribute in Category&nbsp;Widget'>How to Remove &#8220;View all posts filed under&#8221; Prefix from Link Title Attribute in Category&nbsp;Widget</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/3478-add-post-categories-tags-as-hashtags-to-tweets-automatically-stc-plugin/' rel='bookmark' title='How to Add Post Categories and Tags as #Hashtags to Tweets Automatically with the Simple Twitter Connect&nbsp;Plugin'>How to Add Post Categories and Tags as #Hashtags to Tweets Automatically with the Simple Twitter Connect&nbsp;Plugin</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://konstruktors.com/blog/wordpress/3364-sticky-posts-as-category-description/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Automatically Add Image Credit or Source URL to Photo Captions in&#160;WordPress</title>
		<link>http://konstruktors.com/blog/wordpress/3203-how-to-automatically-add-image-credit-or-source-url-to-photo-captions-in-wordpress/</link>
		<comments>http://konstruktors.com/blog/wordpress/3203-how-to-automatically-add-image-credit-or-source-url-to-photo-captions-in-wordpress/#comments</comments>
		<pubDate>Sun, 16 Oct 2011 16:32:44 +0000</pubDate>
		<dc:creator>Kaspars</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://konstruktors.com/?p=3203</guid>
		<description><![CDATA[Crediting and linking the source of any republished photo or illustration on the web is one of the most important best practices of web publishing. Unfortunately, there isn&#8217;t a standard way of doing it in WordPress and authors are left with their own decision on how and where to credit the original author or website. I [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_3205" class="wp-caption aligncenter" style="width: 510px"><img class="size-medium wp-image-3205 " title="Add image author or source URL to photos in WordPress" src="http://konstruktors.com/wp-content/uploads/2011/10/wordpress-image-photo-source-author-url-500x369.png" alt="Add image author or source URL to photos in WordPress" width="500" height="369" /><p class="wp-caption-text">Photo credit added automatically to every photo with a caption (via <a href="http://putukrejums.lv">putukrejums.lv</a>)</p></div>
<p>Crediting and linking the source of any republished photo or illustration on the web is one of the most important best practices of web publishing. Unfortunately, there isn&#8217;t a standard way of doing it in WordPress and authors are left with their own decision on how and where to credit the original author or website.<span id="more-3203"></span></p>
<p>I decided to add <strong>a simple &#8220;Source URL&#8221; input field to every image that is uploaded</strong>. Adding credit with a link to the source of that image now becomes as easy as adding a title or caption for an image:</p>
<p><a href="http://konstruktors.com/wp-content/uploads/2011/10/image-source-url-credit-dashboard.png"><img class="aligncenter size-medium wp-image-3206" title="Attached image Source URL input field" src="http://konstruktors.com/wp-content/uploads/2011/10/image-source-url-credit-dashboard-500x523.png" alt="Attached image Source URL input field" width="500" height="523" /></a></p>
<h3>Implementation</h3>
<p>You need to add the <a href="http://pastebin.com/FZJ3DJBg">following snippet of PHP</a> to your theme&#8217;s <code>functions.php</code>:</p>
<h4>Add the source URL input field to image upload screen</h4>
<pre>add_filter("attachment_fields_to_edit", "add_image_source_url", 10, 2);
function add_image_source_url($form_fields, $post) {
	$form_fields["source_url"] = array(
		"label" =&gt; __("Source URL"),
		"input" =&gt; "text",
		"value" =&gt; get_post_meta($post-&gt;ID, "source_url", true),
                "helps" =&gt; __("Add the URL where the original image was posted"),
	);
 	return $form_fields;
}
add_filter("attachment_fields_to_save", "save_image_source_url", 10 , 2);
function save_image_source_url($post, $attachment) {
	if (isset($attachment['source_url']))
		update_post_meta($post['ID'], 'source_url', esc_url($attachment['source_url']));
	return $post;
}</pre>
<h4>Automatically append the source URL to image captions</h4>
<pre>add_filter('img_caption_shortcode', 'caption_shortcode_with_credits', 10, 3);
function caption_shortcode_with_credits($empty, $attr, $content) {
	extract(shortcode_atts(array(
		'id'	=&gt; '',
		'align'	=&gt; 'alignnone',
		'width'	=&gt; '',
		'caption' =&gt; ''
	), $attr));
	// Extract attachment $post-&gt;ID
	preg_match('/\d+/', $id, $att_id);
	if (is_numeric($att_id[0]) &amp;&amp; $source_url = get_post_meta($att_id[0], 'source_url', true)) {
		$parts = parse_url($source_url);
		$caption .= ' ('. __('via') .' &lt;a href="'. $source_url .'"&gt;'. $parts['host'] .'&lt;/a&gt;)';
	}
	if (1 &gt; (int) $width || empty($caption))
		return $content;
	if ($id)
		$id = 'id="' . esc_attr($id) . '" ';
	return '&lt;div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . (10 + (int) $width) . 'px"&gt;'
		. do_shortcode($content) . '&lt;p class="wp-caption-text"&gt;' . $caption . '&lt;/p&gt;&lt;/div&gt;';
}</pre>
<p>Please note that the source URL will be visible only if you specify image caption upon inserting the image.</p>
<h4>Related posts</h4><ol>
<li><a href='http://konstruktors.com/blog/wordpress/3478-add-post-categories-tags-as-hashtags-to-tweets-automatically-stc-plugin/' rel='bookmark' title='How to Add Post Categories and Tags as #Hashtags to Tweets Automatically with the Simple Twitter Connect&nbsp;Plugin'>How to Add Post Categories and Tags as #Hashtags to Tweets Automatically with the Simple Twitter Connect&nbsp;Plugin</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/1850-automatically-escape-html-entities-of-code-fragments-in-comments/' rel='bookmark' title='Automatically Escape HTML Entities of Code Fragments in&nbsp;Comments'>Automatically Escape HTML Entities of Code Fragments in&nbsp;Comments</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/92-take-away-photo-and-image-positioning-css-styles-for-blogs-idea-for-a-plugin/' rel='bookmark' title='Take-away photo and image positioning CSS styles for blogs &#8212; idea for a&nbsp;plugin'>Take-away photo and image positioning CSS styles for blogs &#8212; idea for a&nbsp;plugin</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://konstruktors.com/blog/wordpress/3203-how-to-automatically-add-image-credit-or-source-url-to-photo-captions-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Remove Inline CSS and Line Breaks in WordPress&#160;Galleries</title>
		<link>http://konstruktors.com/blog/wordpress/2920-remove-inline-css-line-breaks-galleries/</link>
		<comments>http://konstruktors.com/blog/wordpress/2920-remove-inline-css-line-breaks-galleries/#comments</comments>
		<pubDate>Sat, 19 Mar 2011 22:07:55 +0000</pubDate>
		<dc:creator>Kaspars</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[how to]]></category>

		<guid isPermaLink="false">http://konstruktors.com/?p=2920</guid>
		<description><![CDATA[Inline CSS and line breaks &#60;br style="clear" /&#62; that are automatically added to the image galleries in WordPress is an example of how the needs of Automattic and WordPress.com influence the way new features are added to the WordPress core. So instead of editing every single theme on WordPress.com and adding the necessary CSS for [...]]]></description>
			<content:encoded><![CDATA[<p>Inline CSS and line breaks <code>&lt;br style="clear" /&gt;</code> that are automatically added to the image galleries in WordPress is an example of how the needs of Automattic and WordPress.com influence the way new features are added to the WordPress core. So instead of editing every single theme on WordPress.com and adding the necessary CSS for galleries to look good in all of them, they decided to put it WordPress core.</p>
<p>Here is how to replace those double line breaks with a single <code>&lt;br /&gt;</code> and remove the inline CSS:</p>
<pre><code>add_filter('the_content', 'remove_br_gallery', 11);
function remove_br_gallery($output) {
	return preg_replace('/(&lt;br[^&gt;]*&gt;\s*){2,}/', '&lt;br /&gt;', $output);
}
add_filter('use_default_gallery_style', '__return_false');
</code></pre>
<h4>Related posts</h4><ol>
<li><a href='http://konstruktors.com/blog/web-design/3517-regex-remove-all-line-breaks-from-text/' rel='bookmark' title='How to Remove All Line Breaks from Text Using&nbsp;Regex'>How to Remove All Line Breaks from Text Using&nbsp;Regex</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/1770-multiple-galleries-per-post-page/' rel='bookmark' title='Multiple Galleries per&nbsp;Post/Page'>Multiple Galleries per&nbsp;Post/Page</a></li>
<li><a href='http://konstruktors.com/blog/wordpress/1899-smarter-cleaner-gallery/' rel='bookmark' title='Smarter Cleaner&nbsp;Gallery'>Smarter Cleaner&nbsp;Gallery</a></li>
</ol>]]></content:encoded>
			<wfw:commentRss>http://konstruktors.com/blog/wordpress/2920-remove-inline-css-line-breaks-galleries/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
