<?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>KMH LABS</title>
	<atom:link href="http://www.kmhcreative.com/labs/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kmhcreative.com/labs</link>
	<description>Web, Dev &#38; Tech Talk</description>
	<lastBuildDate>Mon, 23 Apr 2012 18:42:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Sneak Peek: Ryuzine 0.9.5</title>
		<link>http://www.kmhcreative.com/labs/2012/02/28/sneak-peek-ryuzine-0-9-5/</link>
		<comments>http://www.kmhcreative.com/labs/2012/02/28/sneak-peek-ryuzine-0-9-5/#comments</comments>
		<pubDate>Tue, 28 Feb 2012 23:20:40 +0000</pubDate>
		<dc:creator>kmhcreative</dc:creator>
				<category><![CDATA[My Projects]]></category>
		<category><![CDATA[Web Dev]]></category>

		<guid isPermaLink="false">http://www.kmhcreative.com/labs/?p=466</guid>
		<description><![CDATA[I just can&#8217;t seem to stop thinking up improvements to the Ryuzine webapp project.  As I write this the 0.9.4 is just about to launch in concert with the Ryuzine Press Plugin for WordPress 3.0+ (and also compatible with ComicPress 2.9).  I barely caught a breath between putting the finishing touches on 0.9.4 when I [...]]]></description>
			<content:encoded><![CDATA[<p>I just can&#8217;t seem to stop thinking up improvements to the Ryuzine webapp project.  As I write this the 0.9.4 is just about to launch in concert with the Ryuzine Press Plugin for WordPress 3.0+ (and also compatible with ComicPress 2.9).  I barely caught a breath between putting the finishing touches on 0.9.4 when I started hacking away on 0.9.5!  So, what&#8217;s on the agenda for version 0.9.5?</p>
<h3>Help Info Overhaul</h3>
<p>The &#8220;Help&#8221; info finally gets overhauled after arguably being kind of ignored since the initial public beta release.  It is going to be replaced with something similar to the Guided Tour &#8220;Bubble&#8221; presently being used on the Ryuzine Machine Demo.  The feeling is that the existing document in the &#8220;Help Panel&#8221; is just too much &#8211; it&#8217;s the proverbial &#8220;wall o&#8217; text&#8221; that, frankly, nobody is probably ever going to read through.  The &#8220;Bubble Help&#8221; version is in the early stages, but it looks like it will only consist of about a dozen sentence-long descriptions and, of course, will bounce around pointing at what it is talking about.  This will be more in line with how mobile app help should be done &#8211; they should generally be pretty intuitive, and where you do include help it should be brief and to the point.</p>
<h3>CSS Customizable Animations</h3>
<p>The control bar is going to be switched to the same animation method used by the phone &#8220;navigation bar.&#8221;  This will fix some minor issues with it in certain specific browsers, but it also (potentially) opens it up to being more configurable &#8211; possibly with a method allowing publishers to add their own custom control buttons/bars to it.</p>
<p>The built-in Lightbox items will also have their animation method changed with the goal being the ability to easily set different animation methods.  Currently the &#8220;zoom in/out&#8221; animation is hard-coded.  The new method will make that configurable in the stylesheet.</p>
<h3>Webcomic &amp; Easel Support (Ryuzine Press)</h3>
<p>The Ryuzine Press plugin for WordPress, in addition to the existing support for blogs using a <a href="http://www.comicpress.org" target="_blank">ComicPress</a> theme and ComicPress Manager, will also support those using the &#8220;<a href="http://mgsisk.com/webcomicms.net/" target="_blank">Webcomic</a>&#8221; plugin and either the &#8220;Inkblot&#8221; or &#8220;Archimedes&#8221; themes; and finally supports &#8220;<a href="http://frumph.net/easel/" target="_blank">Easel</a>&#8221; themes as well (though it requires a tiny hack to one Easel file). That means support for all three of the most popular WordPress webcomics systems!</p>
<h3>Dropped Support</h3>
<p>As much as I don&#8217;t like to drop backwards-compatibility for anyone this next version will officially drop all support for Safari 3.x.  Ryuzine has <em>never</em> worked properly in this version of Safari and with this upcoming release and the previous release it worked in testing with the source code script but stopped working when using the obfuscated release script.  Realistically almost nobody is going to still be using &#8211; and really should not be still using &#8211; this version of Safari anyway.  On the off chance they are, they&#8217;d have to disable CSS and Javascript and view it as a straight HTML page or they&#8217;ll be stuck on the splash screen.</p>
<p>Maintaining backwards compatibility with ancient browsers really isn&#8217;t worth the effort, but I&#8217;ve tried my best to accommodate them where possible.  As I move forward to the release of Version 1.0, however, I&#8217;m going to be focusing my efforts on browsers most people are actually using &#8211; typically the current released, the previous major version, and I&#8217;m also testing in beta versions.  Expect support for other legacy desktop browsers to also fall away in future releases.  I&#8217;ll try to still keep things working in older mobile browsers since users often cannot update those, but there&#8217;s really no excuse for using an outdated browser on your desktop system unless the system is also a museum piece as well.</p>
<h3>Other Additions</h3>
<p>Multiple In-app Bookmarking is being considered.  This would actually be pretty easy to implement since the original (pre-release) version that introduced the bookmarking tool actually did set multiple bookmarks.  Ultimately, though, it was altered to only set and retrieve one bookmark per Ryuzine publication because multiple bookmarking really demands a management panel.  Well, creating that panel and adding the multiple bookmarking is back on the &#8220;To-Do List.&#8221;</p>
<p>Ryuzine Machine will also likely gain some additional options to bring it more in line with the options in Ryuzine Press Plugin for WordPress, so there will be pretty much no learning curve moving from WordPress to Ryuzine Machine authoring and vice versa.</p>
<p>Issue-specific stylesheet gets an update to accommodate &#8220;Retina&#8221; iPad screens.</p>
<p>The &#8220;Localization&#8221; plugin will also need to be overhauled in order to work with the new help content.</p>
<p>The &#8220;Font&#8221; control will do more than just adjust font size up and down.  Color scheme options will also be added: Default (black text on white), Sepia (dark brown text on light tan background), and High Contrast (white text on black background).  This seems pretty standard in e-reader apps so Ryuzine should probably follow that convention.</p>
<p>The add-ons from 0.9.4 should all be compatible, but themes for 0.9.5 may need to be updated to accommodate the new controls/options. When will that be?  I&#8217;m not going to predict.  Also, keep in mind these are the ideas for improving it, some of which are already under way, but there&#8217;s no guarantee all of these changes will be in 0.9.5.  Well, back to coding. . .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kmhcreative.com/labs/2012/02/28/sneak-peek-ryuzine-0-9-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Meta Boxes + Rich Text Editor + Mode Switch Tabs</title>
		<link>http://www.kmhcreative.com/labs/2012/02/15/wordpress-meta-boxes-rich-text-mode-tabs/</link>
		<comments>http://www.kmhcreative.com/labs/2012/02/15/wordpress-meta-boxes-rich-text-mode-tabs/#comments</comments>
		<pubDate>Wed, 15 Feb 2012 23:31:17 +0000</pubDate>
		<dc:creator>kmhcreative</dc:creator>
				<category><![CDATA[Tips, Tricks & Hacks]]></category>
		<category><![CDATA[Web Dev]]></category>

		<guid isPermaLink="false">http://www.kmhcreative.com/labs/?p=452</guid>
		<description><![CDATA[If you read my other post about WordPress Meta Boxes you know I was adding multiple ones to my custom post_type edit page.  Well, I also wanted users to be able to use the TinyMCE Rich Text Editor in those boxes if they wanted, and (just like the regular compose box) be able to toggle [...]]]></description>
			<content:encoded><![CDATA[<p>If you read <a href="http://www.kmhcreative.com/labs/2012/02/15/wordpress-custom-post-type-multiple-meta-boxes/">my other post about WordPress Meta Boxes</a> you know I was adding multiple ones to my custom post_type edit page.  Well, I also wanted users to be able to use the TinyMCE Rich Text Editor in those boxes if they wanted, and (just like the regular compose box) be able to toggle to the HTML source code view (aka the way a Meta Box textarea usually looks).</p>
<p>I found a couple of posts (<a href="http://www.farinspace.com/multiple-wordpress-wysiwyg-visual-editors/" target="_blank">post 1</a>, <a href="http://www.ilovecolors.com.ar/tinymce-plugin-textarea-metaboxes-wordpress/" target="_blank">post2</a>) that sent me about 90% in the right direction, the first told me how to add TinyMCE to the meta boxes, the second showed me how to add the mode switches, but I absolutely could not get the jQuery events to attach to the &#8220;Visual&#8221; and &#8220;HTML&#8221; tabs, no matter how low I placed the script in the page or if I used the recommended jQuery &#8220;ready&#8221; function.  Thankfully, it turns out jQuery is not needed for this to work.</p>
<p>First things first, I added this code, which places the tabs above and wraps my textarea in a named DIV:</p>
<div class="codecolorer-container html4strict mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;editor-toolbar&quot;</span>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;edButtonPreview1&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;edButtonPreview&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;toggleEditor(1,'html');&quot;</span> &gt;</span>HTML<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;edButtonHTML1&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;edButtonHTML active&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;toggleEditor(1,'visual');&quot;</span>&gt;</span>Visual<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;customEditor&quot;</span>&gt;</span><br />
<span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/textarea.html"><span style="color: #000000; font-weight: bold;">textarea</span></a> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;my_meta_box&quot;</span> <span style="color: #000066;">cols</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;40&quot;</span> <span style="color: #000066;">rows</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;5&quot;</span>&gt;&lt;?php echo $my_meta_data; ?&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/textarea.html"><span style="color: #000000; font-weight: bold;">textarea</span></a>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>Yeah, yeah I know I&#8217;m using dreaded evil inline javascript, but it solved my problem with jQuery missing the opportunity to attach event listeners.  For each Meta Box I&#8217;d just advance the number from 1 to 2, 3, 4, etc. (note that we do not start with zero &#8211; the zero TinyMCE editor is the regular one).</p>
<p>The jQuery stuff did work for adding the TinyMCE controls to the Meta Box text areas.  Then I just added a regular ol&#8217; Javascript function for swapping the tabs and turning the rich text editor on and off.  This goes in the footer of the page because it MUST come after TinyMCE has initialized, and the priority of &#8220;99&#8243; helps do that:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_print_footer_scripts'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'my_admin_print_footer_scripts'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">99</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">function</span> my_admin_print_footer_scripts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&lt;script type=&quot;text/javascript&quot;&gt;/* &lt;![CDATA[ */<br />
// This part uses jQuery to add TinyMCE to each Meta Box textarea //<br />
jQuery(function($) {<br />
<br />
var i=1;<br />
$('.customEditor textarea').each(function(e) {<br />
var id = $(this).attr('id');<br />
if (!id){<br />
id = 'customEditor-' + i++;<br />
$(this).attr('id',id);<br />
}<br />
tinyMCE.execCommand('mceAddControl', false, id);<br />
});<br />
});<br />
<br />
// This part lets users toggle between modes //<br />
function toggleEditor(id, dir) {<br />
var id = 'customEditor-'+id;<br />
if (dir==&quot;visual&quot;) {<br />
var cmd = 'mceAddControl';<br />
var cName1 = &quot; active&quot;;<br />
var cName2 = &quot;&quot;;<br />
} else {<br />
var cmd = 'mceRemoveControl';<br />
var cName1 = &quot;&quot;;<br />
var cName2 = &quot; active&quot;;<br />
}<br />
tinyMCE.execCommand(cmd, false, id);<br />
document.getElementById('edButtonPreview').className=&quot;edButtonPreview&quot;+cName1;<br />
document.getElementById('edButtonHTML').className=&quot;edButtonHTML&quot;+cName2;<br />
}<br />
/* ]]&gt; */&lt;/script&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>By now you&#8217;ll see they are functional, but they look awful!  We need to add a little CSS to the head of our admin page to fix it:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_head'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_editor_styles'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">function</span> my_editor_styles<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&lt;style type='text/css'&gt;<br />
#poststuff .editor-toolbar {<br />
height: 30px;<br />
}<br />
#poststuff .edButtonPreview, #poststuff .edButtonHTML {<br />
background-color: #F1F1F1;<br />
border-color: #DFDFDF #DFDFDF #CCC;<br />
color: #999;<br />
}<br />
.edButtonPreview, .edButtonHTML {<br />
height: 18px;<br />
margin: 5px 5px 0 0;<br />
padding: 4px 5px 2px;<br />
float: right;<br />
cursor: pointer;<br />
border-width: 1px;<br />
border-style: solid;<br />
-moz-border-radius: 3px 3px 0 0;<br />
-webkit-border-top-right-radius: 3px;<br />
-webkit-border-top-left-radius: 3px;<br />
-khtml-border-top-right-radius: 3px;<br />
-khtml-border-top-left-radius: 3px;<br />
border-top-right-radius: 3px;<br />
border-top-left-radius: 3px;<br />
}<br />
#poststuff .editor-toolbar .active {<br />
border-color: #CCC #CCC #E9E9E9;<br />
background-color: #E9E9E9;<br />
color: #333;<br />
}<br />
.customEditor {<br />
margin:0 0 25px 0;<br />
border:1px solid #ccc;<br />
background:#fff;<br />
}<br />
.customEditor textarea {<br />
margin:0;<br />
border:0;<br />
width:100%;<br />
background:#fff;<br />
}<br />
<br />
&lt;/style&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>And there it is!  Multiple instances of TinyMCE on multiple Meta Boxes, with tabs above each so users can toggle between &#8220;Visual&#8221; and &#8220;HTML&#8221; modes just like they are used to doing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kmhcreative.com/labs/2012/02/15/wordpress-meta-boxes-rich-text-mode-tabs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress Custom Post Type Multiple Meta Boxes</title>
		<link>http://www.kmhcreative.com/labs/2012/02/15/wordpress-custom-post-type-multiple-meta-boxes/</link>
		<comments>http://www.kmhcreative.com/labs/2012/02/15/wordpress-custom-post-type-multiple-meta-boxes/#comments</comments>
		<pubDate>Wed, 15 Feb 2012 23:00:28 +0000</pubDate>
		<dc:creator>kmhcreative</dc:creator>
				<category><![CDATA[Tips, Tricks & Hacks]]></category>
		<category><![CDATA[Web Dev]]></category>

		<guid isPermaLink="false">http://www.kmhcreative.com/labs/?p=419</guid>
		<description><![CDATA[I&#8217;m writing this post because this really confused me at first. There are some other examples online that maybe, if you&#8217;re here, you&#8217;ve already found: http://www.farinspace.com/how-to-create-custom-wordpress-meta-box/ http://shibashake.com/wordpress-theme/add-metabox-custom-post-type http://codex.wordpress.org/Function_Reference/add_meta_box I think the main reason I was having trouble wrapping my head around it all was because the samples use so many similar names for each part [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m writing this post because this really confused me at first. There are some other examples online that maybe, if you&#8217;re here, you&#8217;ve already found:</p>
<p><a href="http://www.farinspace.com/how-to-create-custom-wordpress-meta-box/">http://www.farinspace.com/how-to-create-custom-wordpress-meta-box/</a></p>
<p><a href="http://shibashake.com/wordpress-theme/add-metabox-custom-post-type">http://shibashake.com/wordpress-theme/add-metabox-custom-post-type</a></p>
<p><a href="http://codex.wordpress.org/Function_Reference/add_meta_box">http://codex.wordpress.org/Function_Reference/add_meta_box</a></p>
<p>I think the main reason I was having trouble wrapping my head around it all was because the samples use so many similar names for each part I wasn&#8217;t sure what was referring to the post_type, the database field, the input variable, or the input name.  Hopefully I can clear it up for anyone else who&#8217;s also struggling with implementing their own Meta Boxes.  Also the samples seem to assume you&#8217;re only adding ONE custom meta box, but I wanted to add three.  My specific application is to add these to the &#8220;edit.php&#8221; page for a custom post type, but the principles would also work if you were adding custom meta boxes to the regular post or page editors too.</p>
<p>I&#8217;m going to assume you&#8217;ve already set up your <a href="http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress">Custom Post_Type</a>, and for my examples I&#8217;ll be using a custom post_type of &#8220;magazine.&#8221;  Now I will concentrate on just the Meta Box part.  First we need to create a function for each of our Meta Boxes:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #000000; font-weight: bold;">function</span> my_first_metabox<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">/* Gets any existing '_myfirst' meta box content */</span><br />
<span style="color: #000088;">$my_first</span> <span style="color: #339933;">=</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span>  <span style="color: #0000ff;">'_myfirst'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">/* If there is none our variable is set to empty quotes */</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$my_first</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$my_first</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">/* Create the security nonce hidden input field */</span><br />
wp_nonce_field<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'magazine'</span><span style="color: #339933;">.</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_first_noncename'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">/* Now for our actual input box.  I'm using a textarea, but this could be<br />
whatever HTML input element you want to use and echo any existing<br />
content into it.*/</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<br />
&lt;textarea id=&quot;my_first&quot; name=&quot;my_first&quot; cols=&quot;40&quot; rows=&quot;5&quot;&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$my_first</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&lt;/textarea&gt;<br />
<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>Then I create two more functions, where the only things I change up are &#8220;first&#8221; for &#8220;second&#8221; and then &#8220;third.&#8221;  You&#8217;ll notice that my meta content name in the example above is &#8220;_myfirst&#8221; rather than &#8220;myfirst&#8221; (like you&#8217;d probably do with meta in a Custom Field).  I believe opening with an underscore was recommended for post meta data because some databases are prefixed with &#8220;ci&#8221; and if you fire up PHPadmin and look at the post_meta tables in the database you&#8217;ll notice all the built-in meta entries start with an underscore, so at the very least we&#8217;ll be consistent.  So, if you&#8217;re following along our functions should now look like this:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #000000; font-weight: bold;">function</span> my_first_metabox<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #000088;">$my_first</span> <span style="color: #339933;">=</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span>  <span style="color: #0000ff;">'_myfirst'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$my_first</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$my_first</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span><br />
wp_nonce_field<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'magazine'</span><span style="color: #339933;">.</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_first_noncename'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&lt;textarea id=&quot;my_first&quot; name=&quot;my_first&quot; cols=&quot;40&quot; rows=&quot;5&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$my_first</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/textarea&gt;<br />
}<br />
<br />
function my_second_metabox($post) {<br />
$my_second = get_post_meta($post-&gt;ID,  '_mysecond', TRUE);<br />
if (!$my_second) $my_second = '';<br />
wp_nonce_field( 'magazine'.$post-&gt;ID, 'my_second_noncename');?&gt;<br />
&lt;textarea id=&quot;my_second&quot; name=&quot;my_first&quot; cols=&quot;40&quot; rows=&quot;5&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$my_second</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/textarea&gt;<br />
}<br />
<br />
function my_third_metabox($post) {<br />
$my_third = get_post_meta($post-&gt;ID,  '_mythird', TRUE);<br />
if (!$my_third) $my_third = '';<br />
wp_nonce_field( 'magazine'.$post-&gt;ID, 'my_third_noncename');?&gt;<br />
&lt;textarea id=&quot;my_third&quot; name=&quot;my_third&quot; cols=&quot;40&quot; rows=&quot;5&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$my_third</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/textarea&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>Those will only allow users to input the data.  We need to be able to collect it, authenticate it, check user permissions, and write the data into our database with the post.  We do that with our &#8220;save&#8221; function:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #000000; font-weight: bold;">function</span> save_metabox_data<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_id</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">/* check if this is an auto save.  If it is the form hasn't been submitted so bail early */</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DOING_AUTOSAVE'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> DOING_AUTOSAVE <span style="color: #009900;">&#41;</span><br />
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$post_id</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">/* verify that this came from the post edit page with proper authentication<br />
and  if any one of these fails the test bail and do nothing */</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>wp_verify_nonce<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'my_first_noncename'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'magazine'</span><span style="color: #339933;">.</span><span style="color: #000088;">$post_id</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>wp_verify_nonce<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'my_second_noncename'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'magazine'</span><span style="color: #339933;">.</span><span style="color: #000088;">$post_id</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>wp_verify_nonce<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'my_third_noncename'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'magazine'</span><span style="color: #339933;">.</span><span style="color: #000088;">$post_id</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$post_id</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #666666; font-style: italic;">/* Check the User Permissions for editing posts.  If not, we bail */</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>current_user_can<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'edit_post'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$post_id</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><br />
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$post_id</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">/* If we got this far everything Authenticated so let's find and save some data */</span><br />
<span style="color: #666666; font-style: italic;">/* First lets get our post and put it into a variable */</span><br />
<span style="color: #000088;">$post</span> <span style="color: #339933;">=</span> get_post<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">/* Now check to make sure it is of our custom post_type */</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_type</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'magazine'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">/* Now we actually update the post meta data.  If the field does not already exist<br />
it automatically calls &quot;add_post_meta&quot; instead.  The first parameter is the post_id<br />
the second is the actual name of our meta field in the database with leading underscore,<br />
the last parameter is referencing the content of our input field in HTML by name */</span><br />
update_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_id</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'_myfirst'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'my_first'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
update_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_id</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'_mysecond'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'my_second'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
update_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_id</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'_mythird'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'my_third'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$post_id</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>However, if you&#8217;ve been hopping back to look at your post editing page you&#8217;ve yet to see anything change.  That&#8217;s because we haven&#8217;t actually fired these functions off yet!  We need to do the typical WordPress thing of functions calling functions:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #000000; font-weight: bold;">function</span> my_custom_meta_boxes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">/* First parameter is just a name.  I used &quot;_section&quot; just to keep it clear that they are just arbitrary section names<br />
which don't seem to actually get used that I can see.  The next part is whatever title you want at the top of the<br />
Meta Box.  Third parameter is our custom post_type name.  Fourth is the &quot;position&quot; of the meta box, and lastly<br />
is the &quot;priority&quot; of how high up on the page it should be (&quot;core&quot; is right after the regular edit box). */</span><br />
add_meta_box<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'myfirst_section'</span><span style="color: #339933;">,</span>  __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'My First Title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_first_metabox'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'magazine'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'normal'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'core'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
add_meta_box<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mysecond_section'</span><span style="color: #339933;">,</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'My 2nd Title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_second_metabox'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'magazine'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'normal'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'core'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
add_meta_box<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mythird_section'</span><span style="color: #339933;">,</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'My Third Title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_third_metabox'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'magazine'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'normal'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'core'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>In case you&#8217;re wondering your options for &#8220;position&#8221; are &#8220;normal,&#8221; &#8220;advanced,&#8221; or &#8220;side&#8221; and the &#8220;priority&#8221; options are &#8220;high,&#8221; &#8220;core,&#8221; &#8220;default,&#8221; and &#8220;low&#8221; (note that none of these will position the meta box <em>above</em> the regular editing window).  Also, if you were doing this for the regular post or page editors you&#8217;d just change the custom post_type name to &#8220;post&#8221; or &#8220;page&#8221; respectively.</p>
<p>Now we just need to do two last little things.  We need to run that function above, which in turn runs all the functions for the meta boxes injecting them into the page, and then we need to set up a trigger for the save function:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_custom_meta_boxes'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'save_post'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">' save_metabox_data'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>That&#8217;s it!  Three custom meta boxes appended to the edit post just below the regular editing window (if your Custom Post_Type supported it), and ONLY appearing on the custom post_type &#8220;magazine&#8221; editing page.</p>
<p>I went on to add the TinyMCE Rich Text Editor to the Meta Boxes with functioning &#8220;Visual&#8221; and &#8220;HTML&#8221; edito mode tabs.  That code is in another post: <a href="http://www.kmhcreative.com/labs/2012/02/15/wordpress-meta-boxes-rich-text-mode-tabs/">http://www.kmhcreative.com/labs/2012/02/15/wordpress-meta-boxes-rich-text-mode-tabs/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kmhcreative.com/labs/2012/02/15/wordpress-custom-post-type-multiple-meta-boxes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Selectively Strip/Show WordPress Shortcodes</title>
		<link>http://www.kmhcreative.com/labs/2012/02/07/selectively-stripshow-wordpress-shortcodes/</link>
		<comments>http://www.kmhcreative.com/labs/2012/02/07/selectively-stripshow-wordpress-shortcodes/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 22:12:56 +0000</pubDate>
		<dc:creator>kmhcreative</dc:creator>
				<category><![CDATA[Tips, Tricks & Hacks]]></category>
		<category><![CDATA[Web Dev]]></category>

		<guid isPermaLink="false">http://www.kmhcreative.com/labs/?p=414</guid>
		<description><![CDATA[In the WordPress Codex where it talks about the &#8220;strip_shortcodes()&#8221; function it includes this example of how to selectively disable shortcodes on the Home page but show them elsewhere: 1234567function remove_shortcode_from_index&#40;$content&#41; &#123; &#160; if &#40; is_home&#40;&#41; &#41; &#123; &#160; &#160; $content = strip_shortcodes&#40; $content &#41;; &#160; &#125; &#160; return $content; &#125; add_filter&#40;'the_content', 'remove_shortcode_from_index'&#41;; But the [...]]]></description>
			<content:encoded><![CDATA[<p>In the WordPress Codex where it talks about the &#8220;strip_shortcodes()&#8221; function it includes this example of how to selectively disable shortcodes on the Home page but show them elsewhere:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> remove_shortcode_from_index<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> is_home<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> strip_shortcodes<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$content</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'remove_shortcode_from_index'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>But the problem with this is it is an &#8220;all or nothing&#8221; deal.  You either show all shortcodes or hide all shortcodes.  What if you want to selectively show some shortcodes and hide others?  Let&#8217;s say you have three custom shortcodes you created.  As you may have found out, if you don&#8217;t register your shortcodes in the functions.php file then the actual [shortcode]&#8230;[/shortcode] code itself will show up in your posts, which you obviously don&#8217;t want.  Let&#8217;s say we have three custom shortcodes:</p>
<p>[shortcode_a] you want to show pretty much everywhere, except on your home page.</p>
<p>[shortcode_b] you ONLY want to show when posts are being shown in your archives.</p>
<p>[shortcode_c] should show up on both single posts and on your home page, but not in archives.</p>
<p>Ok, so how would you do that?  Well one method is to set up your shortcodes in<em> functions.php</em> (or your plugin functions) with conditional statements checking the current page:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> my_shortcode_c<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$atts</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<a href="http://www.php.net/extract"><span style="color: #990000;">extract</span></a><span style="color: #009900;">&#40;</span>shortcode_atts<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'color'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'blue'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #0000ff;">'class'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'monkey'</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> is_home<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> is_single<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$C</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&amp;lt;div class=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$class</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&amp;gt;&amp;lt;span style=&quot;color:'</span><span style="color: #339933;">.</span><span style="color: #000088;">$color</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&amp;gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$content</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;lt;/span&amp;gt;&amp;lt;/div&amp;gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$C</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">return</span> <span style="color: #000088;">$C</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>That sort of structure will handle most of your conditional shortcode needs.  Also, if you wanted it to return the content of the shortcode without the wrapper you could make the &#8220;else&#8221; paret read &#8220;$C= $content&#8221; and it would just echo back whatever is in between the [shortcode]..[/shortcode].  All you need to do is swap out the conditional tags in the &#8220;if&#8221; statement and those pesky shortcodes will dance to whatever tune you play.</p>
<p>But what if they don&#8217;t?  I ran into an issue with a custom post type where, because it wasn&#8217;t a &#8220;template&#8221; or an &#8220;archive&#8221; but a post itself AND it was pulling in other posts in the same category, the conditional function logic above wouldn&#8217;t work!  If I used the shortcode in the body of the custom post itself, then adding something like <em>&#8220;mytype&#8221; == get_post_type()</em>  to the &#8220;if&#8221; statement worked, but ONLY for the shortcodes actually attached to the custom post itself.  If I tried to use that same shortcode on a regular post being displayed within the custom post, so far as WordPress was concerned the post_type was &#8220;post&#8221; and NOT &#8220;mytype.&#8221;  I had a secondary problem that I needed to run two loops with the custom post_type content, and in the first extract only [shortcode_a] content but not [shortcode_b] and in the second loop vise versa.  Which meant I needed to redefine the conditional selection mid-page as well.  So, how would I go about doing that?</p>
<p>Well, as it turns out you aren&#8217;t restricted to placing your shortcode functions in your <em>functions.php</em> or plugin functions files.  They CAN be placed in code on the front-facing template pages, which means we can define or redefine shortcodes on a local basis!  I know I was talking about doing it in a custom post_type page, but you can actually do it with any of the front-facing pages:</p>
<p>In functions.php:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> my_shortcode_a_include<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$atts</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'&amp;lt;div class=&quot;monkey&quot;&amp;gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$content</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;lt;/div&amp;gt;'</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #339933;">&lt;</span>pre<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">function</span> my_shortcode_b_exclude<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #339933;">&lt;</span>pre<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">function</span> my_shortcode_c_exclude<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'shortcode_a'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'my_shortcode_a_include'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'shortcode_b'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'my_shortcode_b_exclude'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'shortcode_c'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'my_shortcode_c_exclude'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Ok, what that does is is creates [shortcode_a] so it works by default.  [shortcode_b] and [shortcode_c], however, are set to return nothing by default (this prevents the actual bracketed code from showing).  Now, for each of the aforementioned conditions we add shortcode functions to the pages. . .</p>
<p>In index.php:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> my_shortcode_a_exclude<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">function</span> my_shortcode_c_include<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$atts</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'&amp;lt;p class=&quot;important&quot;&amp;gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$content</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;lt;/p&amp;gt;'</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'shortcode_a'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'my_shortcode_a_exclude'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'shortcode_c'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'my_shortcode_c_include'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Now on the Home page [shortcode_a] content is hidden, [shortcode_b] is still set to be hidden by<em> functions.php</em> so we don&#8217;t need to change it, and [shortcode_c] content will now show up.</p>
<p>In my <em>single.php</em> file:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> my_shortcode_c_include<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$atts</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'&amp;lt;p&amp;gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$content</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;lt;/p&amp;gt;'</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'shortcode_c'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'my_shortcode_c_include'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>In this case [shortcode_a] will use the default &#8220;include&#8221; setting in functions.php, [shortcode_b] will also use the default &#8220;exclude&#8221; setting in functions.php, so we only need to &#8220;include&#8221; [shortcode_c] and our single posts will now show content from both shortcodes &#8220;a&#8221; and &#8220;c&#8221; but not &#8220;b.&#8221;</p>
<p>In my <em>archive.php</em> file:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> my_shortcode_b_include<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$atts</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'&amp;lt;p&amp;gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$content</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;lt;/p&amp;gt;'</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'shortcode_b'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'my_shortcode_b_include'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Here [shortcode_a] will appear because that&#8217;s the default setting in <em>functions.php</em>, [shortcode_c] will not be included because that is the default setting in <em>functions.php</em>, so we only need to &#8220;include&#8221; [shortcode_b] content.</p>
<p>And, lastly, you can redefine them &#8220;on the fly&#8221; in the same page if you repeat the loop and want to change your selectors.  Just switch the &#8220;add_shortcode&#8221; to the &#8220;include&#8221; or &#8220;exclude&#8221; function as needed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kmhcreative.com/labs/2012/02/07/selectively-stripshow-wordpress-shortcodes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress shortcodes that only work on a custom post_type page</title>
		<link>http://www.kmhcreative.com/labs/2012/02/06/wordpress-shortcodes-that-only-work-on-a-custom-post_type-page/</link>
		<comments>http://www.kmhcreative.com/labs/2012/02/06/wordpress-shortcodes-that-only-work-on-a-custom-post_type-page/#comments</comments>
		<pubDate>Mon, 06 Feb 2012 21:10:34 +0000</pubDate>
		<dc:creator>kmhcreative</dc:creator>
				<category><![CDATA[Tips, Tricks & Hacks]]></category>
		<category><![CDATA[Web Dev]]></category>

		<guid isPermaLink="false">http://www.kmhcreative.com/labs/?p=411</guid>
		<description><![CDATA[My WordPress plugin creates a custom post_type and the custom page which uses that post_type displays regular posts (of post_type=&#8221;post&#8221;) filtered to only show those that have been assigned to the same Category as the custom post_type page itself. Then I created a custom shortcode intended to run Javascript code that is ONLY loaded on [...]]]></description>
			<content:encoded><![CDATA[<p>My WordPress plugin creates a custom post_type and the custom page which uses that post_type displays regular posts (of post_type=&#8221;post&#8221;) filtered to only show those that have been assigned to the same Category as the custom post_type page itself.</p>
<p>Then I created a custom shortcode intended to run Javascript code that is ONLY loaded on pages of my custom post_type.  So the shortcode is basically useless everywhere else on the blog, and consequently I don&#8217;t want it to show the custom shortcode wrapper around that content.  In fact I want the user, in my plugin&#8217;s admin page, to decide whether they want the shortcode content to show up at all when the regular posts are viewed outside of my custom post_type.</p>
<p>My first thought was to simply use Conditional Tags to limit showing the shortcodes to my custom post_type pages.  It works if the shortcode is in the body text of the custom post_type page itself, but if the shortcode is inside a regular post being displayed on a custom post_type page it doesn&#8217;t work (because as far as it&#8217;s concerned it is &#8220;in&#8221; a regular post type, not a custom post type).</p>
<p>I went off searching for other conditional tag and filtering options and the search wasn&#8217;t bearing any fruit.  However I did stumble upon some posts about using a conditional tag to set a global variable and then using the variable as a stand-in check inside the shortcode function.  With that I was able to only execute the shortcode function on my custom post_type pages except then the actual shortcode text (i.e., [myshortcode]&#8230;.[/myshortcode]) would display around the content on every other part of the blog.  Yuck!</p>
<p>Next I tried moving my shortcode function and registration off the<em> plugin.php</em> page and into the <em>single-custom.php </em>which also worked in the sense that the shortcode ONLY processed on my custom post_type pages, but again left the actual shortcode code text in the post everywhere else.</p>
<p>Then it occurred to me that maybe I could declare how the shortcode works generally in my plugin file and redefine it in my custom page file.  So in my <em>plugin.php</em> file:</p>
<p style="padding-left: 30px;"><em>function my_custom_shortcode( $atts, $content = null ) {</em><br />
<em> return $content;</em><br />
<em> }</em><br />
<em>add_shortcode(&#8216;myshortcode&#8217;, &#8216;my_custom_shortcode&#8217;);</em></p>
<p>You might wonder &#8220;What is the point of that?!&#8221;  Well, it prevents the actual shortcode code (the stuff in square brackets) from showing up on pages elsewhere on the blog.  Essentially it is a shortcode that just echoes the content of the shortcode back to the page untouched.</p>
<p>Then in my single-custom.php page I redefine it locally:</p>
<p style="padding-left: 30px;"><em>function my_shortcode_in_page( $atts, $content = null ) {</em><br />
<em> extract(shortcode_atts(array(</em><br />
<em> &#8216;link&#8217; =&gt; &#8216;#&#8217;,</em><br />
<em> &#8216;id&#8217; =&gt; &#8221;</em><br />
<em> ), $atts));</em><br />
<em> $wrapped =&#8217;&lt;div class=&#8221;shortcode&#8221; id=&#8221;&#8216;.$id.&#8217;&#8221;&gt;&lt;span class=&#8221;shorty&#8221;&gt;&lt;a href=&#8221;&#8216;.$link.&#8217;&#8221;&gt;&#8217;.$content.&#8217;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&#8217;;</em><br />
<em> return $wrapped;</em><br />
<em>}</em><br />
<em>add_shortcode(&#8216;myshortcode&#8217;, &#8216;my_shortcode_in_page&#8217;);</em></p>
<p>Now it shows the  unaltered content in regular blog pages but shows my shortcode wrapper on my custom post_type pages &#8211; and ONLY those pages!  But then what if the $content is something that, itself, is kind of useless or odd on pages that won&#8217;t use the shortcode?  For example if you use an image thumbnail for the shortcode link it wouldn&#8217;t be a link at all on other pages, so why have it there at all?  So I added a field to my plugin&#8217;s Options page to let the end user decide if they wanted [myshortcode] content to be hidden elsewhere on the blog.  All that does is set up a variable in the database that is part of the plugin initialization (it checks for the value and sets the global variable).  Then the function in my plugin.php only needs a simple check:</p>
<p style="padding-left: 30px;"><em>function my_custom_shortcode( $atts, $content = null ) {<br />
if ( $hide_myshortcode === &#8220;1&#8243; ) {<br />
// do nothing //<br />
} else {<br />
return $content;<br />
};<br />
}</em></p>
<p>Now, if the user set $hide_myshortcode variable to &#8220;1&#8243; the shortcode returns nothing, which hides whatever is inside the shortcode tag.  If the variable equals some other number (the Options page toggles it between &#8220;0&#8243; and &#8220;1&#8243;) then the content inside the shortcode is returned.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kmhcreative.com/labs/2012/02/06/wordpress-shortcodes-that-only-work-on-a-custom-post_type-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Year, New Version: Ryuzine 0.9.3</title>
		<link>http://www.kmhcreative.com/labs/2012/01/08/new-year-new-version-ryuzine-0-9-3/</link>
		<comments>http://www.kmhcreative.com/labs/2012/01/08/new-year-new-version-ryuzine-0-9-3/#comments</comments>
		<pubDate>Sun, 08 Jan 2012 18:40:01 +0000</pubDate>
		<dc:creator>kmhcreative</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[My Projects]]></category>
		<category><![CDATA[Web Dev]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[WebApp]]></category>

		<guid isPermaLink="false">http://www.kmhcreative.com/labs/?p=402</guid>
		<description><![CDATA[If you head on over to ryumaru.com you can demo and download version 0.9.3 of the &#8220;Ryuzine&#8221; and &#8220;Ryuzine Machine&#8221; web apps. This update represents a significant performance boost to the reader app and some new features/options in the authoring app: Ryuzine Web App Views preference now persistently stored in a cookie file so it [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.kmhcreative.com/labs/wp-content/uploads/2011/12/groupshot.jpg"><img class="aligncenter size-medium wp-image-375" title="groupshot" src="http://www.kmhcreative.com/labs/wp-content/uploads/2011/12/groupshot-300x175.jpg" alt="" width="300" height="175" /></a></p>
<p>If you head on over to <a href="http://www.ryumaru.com/products/ryuzine/" target="_blank">ryumaru.com</a> you can demo and download version 0.9.3 of the &#8220;Ryuzine&#8221; and &#8220;Ryuzine Machine&#8221; web apps.</p>
<p>This update represents a significant performance boost to the reader app and some new features/options in the authoring app:</p>
<h2>Ryuzine Web App</h2>
<ul>
<li>Views preference now persistently stored in a cookie file so it automatically restores the last used view setting.</li>
<li>Can now send custom themes to BlackBerry tablets and Windows Phones.</li>
<li>Send different themes to Android 2.x and 3.x+</li>
<li><strong>+300% faster loading time</strong></li>
<li><strong>30-50% reduction in memory usage</strong> (depending on content)</li>
<li><strong>26% reduction in main script file size</strong></li>
<li>Improved stability on iOS platform</li>
<li>Android 2.x page turn bug fixed (requires Android is not spoofing User Agent string)</li>
<li>“Widescreen” Android phones now correctly fill content in landscape orientation</li>
<li>Fully compatible with 0.9.2 Themes</li>
<li>Compatible with existing 0.9.2 Ryuzine HTML files*</li>
</ul>
<h2>Ryuzine Machine Authoring App</h2>
<ul>
<li><strong>19% reduction in main script file size</strong></li>
<li>Simulator devices can now be skinned</li>
<li>Simulator devices can be zoomed in/out</li>
<li>Ability to add Custom Device profiles to the configuration file</li>
<li>Option to over-ride WYSIWYG loading even on supported browsers (if you prefer to hand-code everything)</li>
</ul>
<p>Now for a little development background on this update.  I was at an electronics store recently where I was playing around with both the iPhone 4s and iPad 2 and was disappointed to see Safari would often crash when loading my apps.  Clearing the browser cache and making sure no multi-tasking was going on helped, but iOS typically just kills any process that uses &#8220;too many&#8221; resources, including Safari, rather than letting one rogue process bring down the whole OS.  That makes sense I suppose, but if you go check the user forums at Apple&#8217;s web site you&#8217;ll see some complaints about Safari crashing even with relatively simple &#8220;rich&#8221; web sites.  Obviously how iOS handles resource issues is out of my hands, but the app I&#8217;ve built is not.</p>
<p>So I set about trying to find things that would reduce the resource footprint.  What I hit on is actually something you&#8217;re not really supposed to do &#8211; at least according to various web design/developer resources I&#8217;ve read over the years:  continuously reflow the page.  Yep, you&#8217;re not supposed to constantly be changing the styles and causing CSS to reflow, but it turned out that was exactly the medicine my web app needs (and leads me to believe some of the &#8220;rules of thumb&#8221; may be a bit outdated concerning how modern browsers adapt).  What I ended up doing was completely rewriting the page-turning function so it selectively displays the contents of an individual Ryuzine page (flips between display: none; and display: block).  By default the contents of all pages (except the cover) are set to &#8220;display:none;&#8221; so when the web app first loads it only grabs the contents of the cover page, rather than ALL the pages (as it did up to 0.9.2).  As you turn pages it sets pages you are going to see to &#8220;display: block&#8221; which &#8211; in the mobile browsers in which I tested it &#8211; caused a request to the server for any image on that page.  In other words it didn&#8217;t load them with the page initially, it requests them <em>a la carte</em>.   Pages you&#8217;re not seeing are set back to &#8220;display:none;&#8221; and removed from the page flow.  Any images are still in the cache, of course, so going back to that page pulls them from there, but the real key seems to be to take it out of the page flow.</p>
<p>What I&#8217;ve learned in trying to optimize my web apps is that Javascript isn&#8217;t the problem, as the &#8220;engine&#8221; for that keeps getting faster and better in pretty much every browser release.  It&#8217;s the CSS Renderer, which is only now starting to get the same sort of performance-related attention,  that tends to get overwhelmed when you layer a lot of CSS effects (particularly CSS3 stuff like shadows, gradients, and rounded corners, and especially when they are literally layered with z-index one atop another).  Thus, taking objects out of this flow when they aren&#8217;t needed makes the CSS renderer work more efficiently.  So despite the fact I&#8217;m making it reflow constantly it has fewer objects to reflow so it becomes a net gain.</p>
<p>Now, this wasn&#8217;t true in older browsers.  Constantly overworking the CSS renderer was bad and some older browsers request everything from the server (everything in the stylesheets &#8211; even if it was for a different media-query case &#8211; and everything in the page even if it was set to &#8220;display:none;&#8221;) which obviously would increase load time, request a lot of items you may not even use, and hold a lot of data in memory you may not need.  It&#8217;s easy to see with misbehaving browsers in the Days of Yore how you wouldn&#8217;t want to put all your media-query cases in a single stylesheet, how you&#8217;d want to dynamically write in case-specific content (ideally from the server-side) as much as possible, and have it render the CSS only once.  Thankfully, in my testing across modern browsers, these issues all appear to have been addressed.  For example, to see what items were actually being requested from my web server I opened Safari&#8217;s &#8220;Activity Window&#8221; and also looked at my web server log file and determined that Safari 3.x would pretty much request every image for every media query while Safari 5 does not.  Which is why it is good to go back from time to time and fact-check the &#8220;rules of thumb&#8221; and see if they still hold true or not.  What it boils down to is I&#8217;m giving the CSS renderer more to do with fewer objects instead of more to do with more objects, which makes the performance enhancements pretty obvious when I put it that way.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kmhcreative.com/labs/2012/01/08/new-year-new-version-ryuzine-0-9-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ryuzine 0.9.2 Available</title>
		<link>http://www.kmhcreative.com/labs/2011/11/24/ryuzine-0-9-2-available/</link>
		<comments>http://www.kmhcreative.com/labs/2011/11/24/ryuzine-0-9-2-available/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 03:24:13 +0000</pubDate>
		<dc:creator>kmhcreative</dc:creator>
				<category><![CDATA[My Projects]]></category>
		<category><![CDATA[Web Dev]]></category>

		<guid isPermaLink="false">http://www.kmhcreative.com/labs/?p=379</guid>
		<description><![CDATA[Head on over to www.ryumaru.com/products/ryuzine/download/ to grab the 0.9.2 release of &#8220;Ryuzine&#8221; and &#8220;Ryuzine Machine.&#8221;   Here are the updates: Ryuzine Web App Added more keyboard controls for panels and add/remove in-app bookmark Added support for BlackBerry Playbook (BB Tablet OS 1.0.7) Two-Page Spreads and Portrait views now available in Legacy Browsers Added Internet Explorer [...]]]></description>
			<content:encoded><![CDATA[<p>Head on over to <a href="http://www.ryumaru.com/products/ryuzine/download/" target="_blank">www.ryumaru.com/products/ryuzine/download/</a> to grab the 0.9.2 release of &#8220;Ryuzine&#8221; and &#8220;Ryuzine Machine.&#8221;   Here are the updates:</p>
<p><strong>Ryuzine Web App</strong></p>
<ul>
<li>Added more keyboard controls for panels and add/remove in-app bookmark</li>
<li>Added support for BlackBerry Playbook (BB Tablet OS 1.0.7)</li>
<li>Two-Page Spreads and Portrait views now available in Legacy Browsers</li>
<li>Added Internet Explorer 7 support (requires legacy_ie addon)</li>
<li>Page numbering position changes with binding/orientation</li>
<li>Phone Nav Page Count Limit bug fixed.</li>
</ul>
<p><strong>Ryuzine Machine Web App</strong></p>
<ul>
<li>Pop-Out option for Simulator (fills browser)</li>
<li>Added Output Options Panel</li>
<li>Automatically corrects for uneven page counts</li>
<li>Fixed bug that prevented custom styles not in &#8220;thisissue.css&#8221; to be cleared by alt views.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.kmhcreative.com/labs/2011/11/24/ryuzine-0-9-2-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OVR 1.3 Released</title>
		<link>http://www.kmhcreative.com/labs/2011/11/23/ovr-1-3-released/</link>
		<comments>http://www.kmhcreative.com/labs/2011/11/23/ovr-1-3-released/#comments</comments>
		<pubDate>Wed, 23 Nov 2011 21:04:32 +0000</pubDate>
		<dc:creator>kmhcreative</dc:creator>
				<category><![CDATA[My Projects]]></category>

		<guid isPermaLink="false">http://www.kmhcreative.com/labs/?p=361</guid>
		<description><![CDATA[The 1.3 release of OVR is now available in the downloads section. This is a major code overhaul that does away with the &#8220;slider&#8221; at the bottom of the player and the legacy &#8220;mouse over image map&#8221; method. Users now interact with OVR images directly, hold/touch dragging left and right to rotate the object without [...]]]></description>
			<content:encoded><![CDATA[<p>The 1.3 release of OVR is now available in the <a href="http://www.kmhcreative.com/labs/downloads/">downloads section</a>. </p>
<p>This is a major code overhaul that does away with the &#8220;slider&#8221; at the bottom of the player and the legacy &#8220;mouse over image map&#8221; method.  Users now interact with OVR images directly, hold/touch dragging left and right to rotate the object without it resetting (rotation always begins from the last position).  Better compatibility with modern browsers and touch-enabled devices, but less compatibility with legacy browsers (particularly Opera).</p>
<p>With this version scripts and styles need to be updated, images do not.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kmhcreative.com/labs/2011/11/23/ovr-1-3-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ryuzine Updated to 0.9.1</title>
		<link>http://www.kmhcreative.com/labs/2011/11/14/ryuzine-updated-to-0-9-1/</link>
		<comments>http://www.kmhcreative.com/labs/2011/11/14/ryuzine-updated-to-0-9-1/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 03:18:58 +0000</pubDate>
		<dc:creator>kmhcreative</dc:creator>
				<category><![CDATA[My Projects]]></category>
		<category><![CDATA[Web Dev]]></category>

		<guid isPermaLink="false">http://www.kmhcreative.com/labs/?p=383</guid>
		<description><![CDATA[A bunch of updates already! Here&#8217;s the rundown. . . Ryuzine Web App Added ability to target webOS devices with custom theme Set up optional features as “add-ons” Fixed Share bubble for third party widgets Added Configurable Zoom &#38; Pan capability for mobile devices Added User Configurable Options Panels with Cookie Preference storage Meta Viewport [...]]]></description>
			<content:encoded><![CDATA[<p>A bunch of updates already! Here&#8217;s the rundown. . .<br />
<strong>Ryuzine Web App</strong></p>
<ol>
<li>Added ability to target webOS devices with custom theme</li>
<li>Set up optional features as “add-ons”</li>
<li>Fixed Share bubble for third party widgets</li>
<li>Added Configurable Zoom &amp; Pan capability for mobile devices</li>
<li>Added User Configurable Options Panels with Cookie Preference storage</li>
<li>Meta Viewport now added dynamically based on device and settings</li>
<li>Rewrote page animation function to disable it for legacy browsers for better performance</li>
<li>Rewrote page flip function so links can contain anchor targets</li>
<li>Added ability to share link to specific page within magazine</li>
<li>Added In-App Bookmark feature</li>
<li>Separated page curves from themes as optional add-on</li>
<li>Switched UI animations from JS to CSS so themes can now change animation effects</li>
<li>Added more keyboard controls</li>
<li>Added support for Windows Phone 7.5 devices</li>
</ol>
<p><strong>Ryuzine Machine Web App</strong></p>
<ol>
<li>Touch-enabled web app so it can be used on mobile devices</li>
<li>Added meta viewport data compatible with webOS</li>
<li>Added Toggle Button for Editor Panels</li>
<li>Added code to hide disabled toolbar buttons in Text Edit mode</li>
<li>Custom Device Profiles now persistent (stored in Cookie)</li>
<li>Option to import custom stylesheet for “My Styles” panel</li>
<li>Option to change default issue-specific style</li>
<li>In-Page Styles can now be preserved</li>
</ol>
<div>Head on over to <a href="http://www.ryumaru.com" target="_blank">Ryu Maru</a> to grab the latest version!</div>
]]></content:encoded>
			<wfw:commentRss>http://www.kmhcreative.com/labs/2011/11/14/ryuzine-updated-to-0-9-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Which Width?</title>
		<link>http://www.kmhcreative.com/labs/2011/11/02/which-width/</link>
		<comments>http://www.kmhcreative.com/labs/2011/11/02/which-width/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 19:30:47 +0000</pubDate>
		<dc:creator>kmhcreative</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.kmhcreative.com/labs/?p=352</guid>
		<description><![CDATA[I previously wrote about the challenges of using media queries on Android given how much variation there is in the devices and the level of control end users have over the viewport. That certainly doesn&#8217;t mean iOS devices are any less challenging! The real underlying problem is that the devices LIE about the screen size. [...]]]></description>
			<content:encoded><![CDATA[<p>I <a title="Media Queries for Android" href="http://www.kmhcreative.com/labs/2011/02/26/media-queries-for-android/">previously wrote</a> about the challenges of using media queries on Android given how much variation there is in the devices and the level of control end users have over the viewport.</p>
<p>That certainly doesn&#8217;t mean iOS devices are any less challenging! The real underlying problem is that the devices LIE about the screen size. They can lie because the pixels reported by the browser are not actual device pixels. There&#8217;s this little thing called a &#8220;device independent pixel&#8221; (or &#8220;dip&#8221;) and it has nothing to do with the &#8220;dots per inch&#8221; (or &#8220;dpi&#8221;) by which I mean the actual pixel count of the screen. The former is the &#8220;pixel density&#8221; and the latter is the &#8220;pixel resolution.&#8221;</p>
<p>Furthermore mobile devices tend to do a lot of scaling of web sites that desktop browsers do not. For example, if you look at a web site that has no coding in it aimed at mobile devices then iOS devices will zoom the page out and pretend the screen (regardless of how big it actually is, the resolution, or the pixel density) is 960 pixels wide. On an iPhone 3G it is actually 320 physical pixels in portrait and 480 in landscape, on an iPad it is 768 physical pixels wide in portrait and 1024 in landscape. But either way it will pretend that it is 960 pixels wide. However, if you add a viewport tag and tie the width to &#8220;device-width&#8221; you STILL aren&#8217;t going to get the actual physical pixel width. An iPhone will report 320 pixels wide in either orientation and an iPad will say 768 in either orientation. So they&#8217;re only truthful about device-width in portrait orientation.</p>
<p>So you think you&#8217;ll address that problem with media queries in your stylesheets? Nope. Even with media query conditions for widths of 1024 and 768 you&#8217;ll only ever see the one for 768 used because the device is lying about its width in landscape mode.   You can try to create two different media queries for 768 pixels by adding (orientation: landscape) to one, but the viewport will STILL only be 768 pixels wide (because that&#8217;s the fake &#8220;device-width&#8221; it says it is) so you&#8217;ll see your 1024 layout sure enough, but if you rotate from portrait to landscape it will be slightly zoomed in and the remaining 256 pixels will be off the right of the screen.</p>
<p>You could also try forgetting about the whole &#8220;device-width&#8221; thing since it&#8217;s a lie and just change your meta tag to:</p>
<p><em>&lt;meta name=&#8221;viewport&#8221;  content=&#8221;initial-scale=1.0,minimum-scale=1.0&#8243; /&gt;</em></p>
<p>Which will allow the page to use your media queries for 768 and 1024 but still causes the zoom-in problem when rotating from portrait to landscape.  You can zoom out, of course, to see the whole width but this is hardly a desirable user experience.</p>
<p>Ok, so how do you get it to show the different layout for 1024 pixels wide AND zoom out to show it all on changing orientation?  Well, you apparently have to sacrifice user functionality to do it. <img src='http://www.kmhcreative.com/labs/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p><em>&lt;meta name=&#8221;viewport&#8221; content=&#8221;initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no&#8221; /&gt;</em></p>
<p>That will force it to zoom out, but it also means users can no longer pinch/spread zoom in/out.  The &#8220;user-scalable&#8221; part is kind of redundant since the maximum-scale is set to 1.0 anyway, but it drives home the point that user functionality is being sacrificed (and if I recall Android will ignore the rest if that isn&#8217;t there).</p>
<p>A better option is to accept that your 768 pixel layout will be used in landscape mode too and just design for that, ideally by using a fluid layout that can just adapt to whatever width the device is going to insist it has.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kmhcreative.com/labs/2011/11/02/which-width/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

