<?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>Musings of ErisDS &#187; WordPress</title>
	<atom:link href="http://erisds.co.uk/category/wordpress/feed" rel="self" type="application/rss+xml" />
	<link>http://erisds.co.uk</link>
	<description>Web development, Symfony, Wordpress and general geekery</description>
	<lastBuildDate>Sat, 07 Jan 2012 10:29:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>WordPress: Migrate! Updated</title>
		<link>http://erisds.co.uk/wordpress/wordpress-migrate-updated</link>
		<comments>http://erisds.co.uk/wordpress/wordpress-migrate-updated#comments</comments>
		<pubDate>Fri, 23 Sep 2011 06:47:20 +0000</pubDate>
		<dc:creator>ErisDS</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[migrate]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://erisds.co.uk/?p=2197</guid>
		<description><![CDATA[A new version of Migrate! is now available to download from Github. What does this fix? A few people have reported having problems using the Migrate! script with their local setups as it constantly shows an error message saying &#8220;Your current URL is not a valid URL&#8221; much like this: Migrate! Was originally very strict [...]


Related posts:<ol><li><a href='http://erisds.co.uk/wordpress/migrate-announcement' rel='bookmark' title='Permanent Link: WordPress: Migrate! Easy WordPress Site Migration'>WordPress: Migrate! Easy WordPress Site Migration</a><small>If you work with multiple environments (development, staging, production etc)...</small></li>
<li><a href='http://erisds.co.uk/wordpress/upgrading-old-wordpress-installs-not-as-scary-as-you-think' rel='bookmark' title='Permanent Link: Upgrading old WordPress installs &#8211; not as scary as you think!'>Upgrading old WordPress installs &#8211; not as scary as you think!</a><small>Earlier this week I received an email requesting some help...</small></li>
<li><a href='http://erisds.co.uk/wordpress/spotlight-wordpress-pods-plugin' rel='bookmark' title='Permanent Link: Spotlight: WordPress Pods Plugin'>Spotlight: WordPress Pods Plugin</a><small>Have you ever needed to build a website which fit...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>A new version of <strong>Migrate!</strong> is now available <a href="https://github.com/ErisDS/Migrate/zipball/master" onClick="_gaq.push(['_trackPageview', '/downloads/migrate_github_zip_002']);" title="Download from GitHub">to download from Github</a>.</p>
<h2>What does this fix?</h2>
<p>A few people have reported having problems using the Migrate! script with their local setups as it constantly shows an error message saying &#8220;Your current URL is not a valid URL&#8221; much like this:</p>
<p><img src="http://erisds.co.uk/wp-content/uploads/2011/09/MigrateError-600x202.jpg" alt="Your current URL is not a valid URL" title="Migrate Invalid URL Error" width="600" height="202" class="aligncenter size-large wp-image-2199" /></p>
<p>Migrate! Was originally very strict about what constituted a valid URL and was expecting something with a TLD, which of course http://localhost doesn&#8217;t have, thus making Migrate! rather unhelpful in some local environments.</p>
<p>This issue has has been resolved in the latest version, which can as always be obtained from Github: <a href="https://github.com/ErisDS/Migrate/zipball/master" onClick="_gaq.push(['_trackPageview', '/downloads/migrate_github_zip_003']);" title="Download from GitHub">Download Migrate!</a></p>


<p>Related posts:<ol><li><a href='http://erisds.co.uk/wordpress/migrate-announcement' rel='bookmark' title='Permanent Link: WordPress: Migrate! Easy WordPress Site Migration'>WordPress: Migrate! Easy WordPress Site Migration</a><small>If you work with multiple environments (development, staging, production etc)...</small></li>
<li><a href='http://erisds.co.uk/wordpress/upgrading-old-wordpress-installs-not-as-scary-as-you-think' rel='bookmark' title='Permanent Link: Upgrading old WordPress installs &#8211; not as scary as you think!'>Upgrading old WordPress installs &#8211; not as scary as you think!</a><small>Earlier this week I received an email requesting some help...</small></li>
<li><a href='http://erisds.co.uk/wordpress/spotlight-wordpress-pods-plugin' rel='bookmark' title='Permanent Link: Spotlight: WordPress Pods Plugin'>Spotlight: WordPress Pods Plugin</a><small>Have you ever needed to build a website which fit...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://erisds.co.uk/wordpress/wordpress-migrate-updated/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress: Migrate! Easy WordPress Site Migration</title>
		<link>http://erisds.co.uk/wordpress/migrate-announcement</link>
		<comments>http://erisds.co.uk/wordpress/migrate-announcement#comments</comments>
		<pubDate>Fri, 07 Jan 2011 22:32:56 +0000</pubDate>
		<dc:creator>ErisDS</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[featured]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://erisds.co.uk/?p=1745</guid>
		<description><![CDATA[<img src="http://erisds.co.uk/wp-content/uploads/2010/11/migrate1-150x150.jpg" alt="" title="migrate" width="150" height="150" class="alignleft size-thumbnail wp-image-1858" />If you work with multiple environments (development, staging, production etc) when building WordPress sites, you'll know that WordPress uses hardcoded absolute URLs in the database for various tasks. There are lots of arguments as to why this is done, and whether it's the best solution, but for now it remains quite difficult to migrate WordPress between environments.


Related posts:<ol><li><a href='http://erisds.co.uk/wordpress/wordpress-migrate-updated' rel='bookmark' title='Permanent Link: WordPress: Migrate! Updated'>WordPress: Migrate! Updated</a><small>A new version of Migrate! is now available to download...</small></li>
<li><a href='http://erisds.co.uk/wordpress/upgrading-old-wordpress-installs-not-as-scary-as-you-think' rel='bookmark' title='Permanent Link: Upgrading old WordPress installs &#8211; not as scary as you think!'>Upgrading old WordPress installs &#8211; not as scary as you think!</a><small>Earlier this week I received an email requesting some help...</small></li>
<li><a href='http://erisds.co.uk/wordpress/spotlight-wordpress-pods-plugin' rel='bookmark' title='Permanent Link: Spotlight: WordPress Pods Plugin'>Spotlight: WordPress Pods Plugin</a><small>Have you ever needed to build a website which fit...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a title="Migrate" href="http://erisds.co.uk/projects/migrate"><img class=" size-large wp-image-1858" title="migrate" src="http://erisds.co.uk/wp-content/uploads/2010/11/migrate1-600x199.jpg" alt="" width="600" height="199" /></a></p>
<p><ins datetime="2011-09-04T17:28:01+00:00"><strong>Note: Migrate! Was last updated 04/09/2011</strong></ins></p>
<p>&nbsp;</p>
<p>If you work with multiple environments (development, staging, production etc) when building WordPress sites, you&#8217;ll know that WordPress uses hardcoded absolute URLs in the database for various tasks. There are lots of arguments as to why this is done, and whether it&#8217;s the best solution, but for now it remains quite difficult to migrate WordPress between environments.</p>
<p>Having worked in this way for a number of years, I&#8217;ve developed a script to help change the URL of a WordPress installation. This script, called <a title="WordPress Migrate! Script" href="http://erisds.co.uk/projects/migrate">Migrate!</a> is now available to download.</p>
<p><a title="WordPress Migrate! Script" href="http://erisds.co.uk/projects/migrate">Migrate!</a> Essentially takes two URLs &#8211; the one you&#8217;re migrating from, and the one you&#8217;re migrating to, and replaces one with the other in all relevant parts of the database. The database queries used to do this have been actively tested in migrating sites to various production environments. The user interface and interactions are in development.</p>
<p><strong>Necessary disclaimer:</strong> I take no responsibility for problems caused by the script, but you should have a backup beforehand anyway by the very nature of the script! Also.. anything you do with the script can be easily and completely reversed by switching the &#8220;from&#8221; and &#8220;to&#8221; URLS.</p>
<h3>Why is this not a plugin?</h3>
<p>Once WordPress&#8217; files and database have been moved to a new URL, it is no longer possible to successfully login to and navigate around the WordPress backend without migrating the URL in the database. Therefore, the problem with having a migration script as a plugin is that the work to replace the URLs in the database would have to be done on the original install before the files and database are moved to the new server.</p>
<p>This means running the plugin, moving the install, and then running the plugin on the old install again if you still need it for futher development etc. In addition, many people, who don&#8217;t work with WordPress all the time, don&#8217;t realise there is a problem with migrating WordPress to a new URL until they try to do it.</p>
<p>So these are the main reasons for not having it as a plugin. However, there is a plugin version, which will hopefully also handle some other task involved in migrating a site, planned for the future.</p>
<h3>Go get it</h3>
<p>The <a title="WordPress Migrate! Script" href="http://erisds.co.uk/projects/migrate">Migrate!</a> script has it&#8217;s <a title="WordPress Migrate! Script" href="http://erisds.co.uk/projects/migrate">own page</a> on this site. From there you can download the plugin, find out how to contribute, log an issue in the comments and read about the latest developments.</p>


<p>Related posts:<ol><li><a href='http://erisds.co.uk/wordpress/wordpress-migrate-updated' rel='bookmark' title='Permanent Link: WordPress: Migrate! Updated'>WordPress: Migrate! Updated</a><small>A new version of Migrate! is now available to download...</small></li>
<li><a href='http://erisds.co.uk/wordpress/upgrading-old-wordpress-installs-not-as-scary-as-you-think' rel='bookmark' title='Permanent Link: Upgrading old WordPress installs &#8211; not as scary as you think!'>Upgrading old WordPress installs &#8211; not as scary as you think!</a><small>Earlier this week I received an email requesting some help...</small></li>
<li><a href='http://erisds.co.uk/wordpress/spotlight-wordpress-pods-plugin' rel='bookmark' title='Permanent Link: Spotlight: WordPress Pods Plugin'>Spotlight: WordPress Pods Plugin</a><small>Have you ever needed to build a website which fit...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://erisds.co.uk/wordpress/migrate-announcement/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>WordPress Automatic Upgrades &#8211; One of the pitfalls</title>
		<link>http://erisds.co.uk/wordpress/wordpress-automatic-upgrades-one-of-the-pitfalls</link>
		<comments>http://erisds.co.uk/wordpress/wordpress-automatic-upgrades-one-of-the-pitfalls#comments</comments>
		<pubDate>Thu, 30 Dec 2010 10:43:39 +0000</pubDate>
		<dc:creator>ErisDS</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://erisds.co.uk/?p=1804</guid>
		<description><![CDATA[<a href="http://erisds.co.uk/wp-content/uploads/2010/07/wordpress-logo-notext-rgb.png"><img src="http://erisds.co.uk/wp-content/uploads/2010/07/wordpress-logo-notext-rgb-150x150.png" alt="" title="WordPress logo" width="150" height="150" class="alignleft size-thumbnail wp-image-1389" /></a>This morning I woke up to announcements of a <a href="http://wordpress.org/news/2010/12/3-0-4-update/">security upgrade (3.0.4)</a> for WordPress. It is highly recommended that everyone upgrade their installs.

I set to the task of upgrading this and a couple of other websites I look after. All of my sites are on 3.0, but not all of them have seen an update since. Nevertheless I know that upgrading is usually a one click job, and even if you have a more complex setup with massive plugins or theme frameworks like thematic where the order of updating can be important, it usually <a href="http://erisds.co.uk/wordpress/upgrading-old-wordpress-installs-not-as-scary-as-you-think">goes pretty smoothly</a>.


Related posts:<ol><li><a href='http://erisds.co.uk/wordpress/upgrading-old-wordpress-installs-not-as-scary-as-you-think' rel='bookmark' title='Permanent Link: Upgrading old WordPress installs &#8211; not as scary as you think!'>Upgrading old WordPress installs &#8211; not as scary as you think!</a><small>Earlier this week I received an email requesting some help...</small></li>
<li><a href='http://erisds.co.uk/wordpress/wordpress-2-8' rel='bookmark' title='Permanent Link: WordPress 2.8'>WordPress 2.8</a><small>Over the weekend I updated my blog to Wordpress 2.8....</small></li>
<li><a href='http://erisds.co.uk/wordpress/migrate-announcement' rel='bookmark' title='Permanent Link: WordPress: Migrate! Easy WordPress Site Migration'>WordPress: Migrate! Easy WordPress Site Migration</a><small>If you work with multiple environments (development, staging, production etc)...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://erisds.co.uk/wp-content/uploads/2010/07/wordpress-logo-notext-rgb.png"><img src="http://erisds.co.uk/wp-content/uploads/2010/07/wordpress-logo-notext-rgb-150x150.png" alt="" title="WordPress logo" width="150" height="150" class="alignleft size-thumbnail wp-image-1389" /></a>This morning I woke up to announcements of a <a href="http://wordpress.org/news/2010/12/3-0-4-update/">security upgrade (3.0.4)</a> for WordPress. It is highly recommended that everyone upgrade their installs.</p>
<p>I set to the task of upgrading this and a couple of other websites I look after. All of my sites are on 3.0, but not all of them have seen an update since. Nevertheless I know that upgrading is usually a one click job, and even if you have a more complex setup with massive plugins or theme frameworks like thematic where the order of updating can be important, it usually <a href="http://erisds.co.uk/wordpress/upgrading-old-wordpress-installs-not-as-scary-as-you-think">goes pretty smoothly</a>.</p>
<p>So I was pretty shocked when my relatively uncomplicated wedding site failed to update from 3.0.1.</p>
<p><kbd>Fatal error: Call to undefined function update_core() in /blah/blah/blah/wp-admin/includes/class-wp-upgrader.php on line 895</kbd></p>
<p>The error message I received is pretty nonsensical &#8211; the site hadn&#8217;t been hacked (either by a hacker or my keen development skills) and there&#8217;s absolutely no reason why a WordPress function should be missing. I had already upgraded my blog from 3.0.3 successfully, but I know the WP team wouldn&#8217;t release an upgrade that only worked from the latest version.</p>
<p>I checked permissions on my upgrade folder were set to 777 &#8211; this wasn&#8217;t the problem, although it often is when receiving errors during automatic upgrade. After a bit of digging around, turns out the error message I got is one of a few error messages that can appear when you try to automatically update but <strong>don&#8217;t have enough disk space</strong>. Pretty simple problem to solve, but not an easy one to figure out when you&#8217;re staring at the WordPress admin screen!</p>
<p>Turns out, another version of this error &#8211; when it gets a bit further along this process &#8211; may also kick out the following error:</p>
<p><kbd>Incompatible Archive.: PCLZIP_ERR_BAD_FORMAT (-10) : Unable to find End of Central Dir Record signature</kbd></p>
<p>Which makes a little more sense &#8211; the archive uploaded is never complete because there&#8217;s no room for the end of it. </p>
<p>I&#8217;ve had a scout around the internet to see if there are any other manifestations of this problem, not dug anything else up yet, but here are a few more articles on solving problems with automatic upgrades:</p>
<ul>
<li><a href="https://billing.handsonwebhosting.com/knowledgebase.php?action=displayarticle&#038;id=268">Memory Allocation Error: WordPress Upgrade Failure</a></li>
<li><a href="http://philipoakley.org/2010/10/15/wordpress-2/wordpress-plugin-upgrade-failed-error-finally-solved/">WordPress Plugin upgrade failed error</a></li>
<li><a href="http://hellboundbloggers.com/2010/06/21/wordpress-3-0-problems-and-solutions/">WordPress 3.0 Problems And Their Solutions</a></li>
<li><a href="http://bestpctips.co.cc/2010/08/21/fix-wordpress-error-after-automatic-upgrade-plugin-failed/">Fix WordPress Error After Automatic upgrade Plugin Failed</a></li>
<li><a href="http://www.wpfunda.com/wordpress-upgrade-errorbriefly-unavailable-for-scheduled-maintenance.html">Briefly unavailable for scheduled maintenance &#8211; Fix for sites stuck in maintenance mode</a></li>
</ul>


<p>Related posts:<ol><li><a href='http://erisds.co.uk/wordpress/upgrading-old-wordpress-installs-not-as-scary-as-you-think' rel='bookmark' title='Permanent Link: Upgrading old WordPress installs &#8211; not as scary as you think!'>Upgrading old WordPress installs &#8211; not as scary as you think!</a><small>Earlier this week I received an email requesting some help...</small></li>
<li><a href='http://erisds.co.uk/wordpress/wordpress-2-8' rel='bookmark' title='Permanent Link: WordPress 2.8'>WordPress 2.8</a><small>Over the weekend I updated my blog to Wordpress 2.8....</small></li>
<li><a href='http://erisds.co.uk/wordpress/migrate-announcement' rel='bookmark' title='Permanent Link: WordPress: Migrate! Easy WordPress Site Migration'>WordPress: Migrate! Easy WordPress Site Migration</a><small>If you work with multiple environments (development, staging, production etc)...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://erisds.co.uk/wordpress/wordpress-automatic-upgrades-one-of-the-pitfalls/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>WordPress: link_before and link_after don&#8217;t display in wp_list_pages</title>
		<link>http://erisds.co.uk/wordpress/wordpress-link_before-and-link_after-dont-display-in-wp_list_pages</link>
		<comments>http://erisds.co.uk/wordpress/wordpress-link_before-and-link_after-dont-display-in-wp_list_pages#comments</comments>
		<pubDate>Thu, 09 Sep 2010 13:39:22 +0000</pubDate>
		<dc:creator>ErisDS</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://erisds.co.uk/?p=1621</guid>
		<description><![CDATA[Have you ever stumbled across the issue where <kbd>wp_list_pages</kbd> isn't spitting out the text you define for <kbd>link_before</kbd> and <kbd>link_after</kbd>? I came across this some time ago: one minute my lovely pipe bars '&#124;' where there, the next they weren't. It turns out this is due to the EXTREMELY popular All in One SEO Pack plugin (if you're not using this you should be!).


Related posts:<ol><li><a href='http://erisds.co.uk/wordpress/snippet-wordpress-customise-the-excerpt-length-and-more-string' rel='bookmark' title='Permanent Link: Snippet: WordPress &#8211; Customise the Excerpt Length and More string'>Snippet: WordPress &#8211; Customise the Excerpt Length and More string</a><small>These functions and hooks let you customise the output of...</small></li>
<li><a href='http://erisds.co.uk/wordpress/snippet-wordpress-3-0-menus-add-a-login-logout-link' rel='bookmark' title='Permanent Link: Snippet: WordPress 3.0 Menus &#8211; Add a login / logout link'>Snippet: WordPress 3.0 Menus &#8211; Add a login / logout link</a><small>The new WordPress 3.0 menu system is pretty powerful and...</small></li>
<li><a href='http://erisds.co.uk/wordpress/migrate-announcement' rel='bookmark' title='Permanent Link: WordPress: Migrate! Easy WordPress Site Migration'>WordPress: Migrate! Easy WordPress Site Migration</a><small>If you work with multiple environments (development, staging, production etc)...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Have you ever stumbled across the issue where <kbd>wp_list_pages</kbd> isn&#8217;t spitting out the text you define for <kbd>link_before</kbd> and <kbd>link_after</kbd>? I came across this some time ago: one minute my lovely pipe bars &#8216;|&#8217; where there, the next they weren&#8217;t. It turns out this is due to the EXTREMELY popular All in One SEO Pack plugin (if you&#8217;re not using this you should be!).</p>
<p>The All in One SEO Pack plugin lets you define menu labels for pages which are used instead of the page titles. It uses a filter to swap these out, and unfortunately when it swaps out the titles it also swaps out whatever text was declared for <kbd>link_before</kbd> and <kbd>link_after</kbd>. This is particularly annoying as it happens even if you don&#8217;t supply a custom menu label.</p>
<p>This is only a small bug in the plugin to fix, and I have provided code which will fix it to the plugin author. In the meantime, if you run into this issue there is a simple work around. <strong>Please Note:</strong> this will prevent AIOSEOP from swapping your page titles for your custom menu labels, so don&#8217;t do this if you still want to use them!!</p>
<p>In your template, before you use the <kbd>wp_list_pages</kbd> function, add the following line of code:</p>
<div class="codecolorer-container php twitlight" 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 /></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> remove_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_list_pages'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'aioseop_list_pages'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>Then afterwards add the following:</p>
<div class="codecolorer-container php twitlight" 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 /></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> add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_list_pages'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'aioseop_list_pages'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
<p>This temporarily disables then reenables the filter so your menu is output properly. </p>
<p>So all together you should end up with something like:</p>
<div class="codecolorer-container php twitlight" 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">&lt;ul&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <br />
remove_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_list_pages'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'aioseop_list_pages'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
wp_list_pages<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><span style="color: #0000ff;">'title_li'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'sort_column'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'menu_order'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'depth'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'link_after'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">' / '</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_list_pages'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'aioseop_list_pages'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&lt;/ul&gt;</div></td></tr></tbody></table></div>
<p>Hopefully this will stop other folks from going mad wondering why bits of their menu have disappeared!</p>
<p class="small"><strong>Please note:</strong> I have known this issue to occur in AIOSEOP versions 1.6.6.2 > 1.6.12.1</p>


<p>Related posts:<ol><li><a href='http://erisds.co.uk/wordpress/snippet-wordpress-customise-the-excerpt-length-and-more-string' rel='bookmark' title='Permanent Link: Snippet: WordPress &#8211; Customise the Excerpt Length and More string'>Snippet: WordPress &#8211; Customise the Excerpt Length and More string</a><small>These functions and hooks let you customise the output of...</small></li>
<li><a href='http://erisds.co.uk/wordpress/snippet-wordpress-3-0-menus-add-a-login-logout-link' rel='bookmark' title='Permanent Link: Snippet: WordPress 3.0 Menus &#8211; Add a login / logout link'>Snippet: WordPress 3.0 Menus &#8211; Add a login / logout link</a><small>The new WordPress 3.0 menu system is pretty powerful and...</small></li>
<li><a href='http://erisds.co.uk/wordpress/migrate-announcement' rel='bookmark' title='Permanent Link: WordPress: Migrate! Easy WordPress Site Migration'>WordPress: Migrate! Easy WordPress Site Migration</a><small>If you work with multiple environments (development, staging, production etc)...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://erisds.co.uk/wordpress/wordpress-link_before-and-link_after-dont-display-in-wp_list_pages/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Snippet: WordPress 3.0 Menus &#8211; Add a login / logout link</title>
		<link>http://erisds.co.uk/wordpress/snippet-wordpress-3-0-menus-add-a-login-logout-link</link>
		<comments>http://erisds.co.uk/wordpress/snippet-wordpress-3-0-menus-add-a-login-logout-link#comments</comments>
		<pubDate>Mon, 06 Sep 2010 13:26:30 +0000</pubDate>
		<dc:creator>ErisDS</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[menus]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://erisds.co.uk/?p=1494</guid>
		<description><![CDATA[The new WordPress 3.0 menu system is pretty powerful and provides some very interesting new options for creating menus in WordPress. Previously, I have always used wp_list_pages and a custom Walker class to provide hierarchical menus based on the page structure, but that's a topic for another post. This super-short snippet shows you how to add a login / logout link to one of your WordPress menus.



Related posts:<ol><li><a href='http://erisds.co.uk/wordpress/snippet-wordpress-customise-the-excerpt-length-and-more-string' rel='bookmark' title='Permanent Link: Snippet: WordPress &#8211; Customise the Excerpt Length and More string'>Snippet: WordPress &#8211; Customise the Excerpt Length and More string</a><small>These functions and hooks let you customise the output of...</small></li>
<li><a href='http://erisds.co.uk/wordpress/spotlight-wordpress-admin-menu-remove-add-new-pages-or-posts-link' rel='bookmark' title='Permanent Link: Spotlight: WordPress Admin Menu &#8211; Remove &#8220;Add New&#8221; pages or posts link'>Spotlight: WordPress Admin Menu &#8211; Remove &#8220;Add New&#8221; pages or posts link</a><small>Back in June I posted about tidying up the WordPress...</small></li>
<li><a href='http://erisds.co.uk/wordpress/snippet-wordpress-admin-tidy-dashboard-widgets-by-role' rel='bookmark' title='Permanent Link: Snippet: WordPress Admin &#8211; Tidy Dashboard Widgets By Role'>Snippet: WordPress Admin &#8211; Tidy Dashboard Widgets By Role</a><small>Recently I worked on a Wordpress site where I wanted...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>The new WordPress 3.0 menu system is pretty powerful and provides some very interesting new options for creating menus in WordPress. Previously, I have always used wp_list_pages and a custom Walker class to provide hierarchical menus based on the page structure, but that&#8217;s a topic for another post. This super-short snippet shows you how to add a login / logout link to one of your WordPress menus.</p>
<p>WordPress contains some special functions for creating login and logout links: <kbd>wp_login_url</kbd> and <kbd>wp_logout_url</kbd>. They both take a string argument which is the URL you want them to redirect to after performing the login/logout action. In the example below I am adding the login / logout link to the beginning of the menu and redirecting to the home page (index.php) in both cases.</p>
<div class="codecolorer-container php twitlight" 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 /></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: #666666; font-style: italic;">// functions.php</span><br />
<span style="color: #000000; font-weight: bold;">function</span> add_login_logout_link<span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_user_logged_in<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$newitems</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;li&gt;&lt;a title=&quot;Logout&quot; href=&quot;'</span><span style="color: #339933;">.</span> wp_logout_url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index.php'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;Logout&lt;/a&gt;&lt;/li&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$newitems</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$items</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$newitems</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;li&gt;&lt;a title=&quot;Login&quot; href=&quot;'</span><span style="color: #339933;">.</span> wp_login_url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index.php'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;Login&lt;/a&gt;&lt;/li&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$newitems</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$items</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;">$newitems</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;">'wp_nav_menu_items'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'add_login_logout_link'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>If the current user is logged in, they will see a logout link and vice versa. To use this snippet, copy and paste the code into your theme&#8217;s functions.php file. You can easily change it to redirect to the dashboard after login, or have the login / logout link at the end of the menu like this:</p>
<div class="codecolorer-container php twitlight" 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 /></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: #666666; font-style: italic;">// functions.php</span><br />
<span style="color: #000000; font-weight: bold;">function</span> add_login_logout_link<span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_user_logged_in<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$newitems</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$items</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$newitems</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;li&gt;&lt;a title=&quot;Logout&quot; href=&quot;'</span><span style="color: #339933;">.</span> wp_logout_url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index.php'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;Logout&lt;/a&gt;&lt;/li&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$newitems</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$items</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$newitems</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;li&gt;&lt;a title=&quot;Login&quot; href=&quot;'</span><span style="color: #339933;">.</span> wp_login_url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp-admin/index.php'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;Login&lt;/a&gt;&lt;/li&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$newitems</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;">'wp_nav_menu_items'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'add_login_logout_link'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>You can also place the login / logout link elsewhere in the menu structure. However, you need to split the menu items apart, locate the right position, insert your menu item and then stick the menu items back together again to return. An example of putting the link second is shown below:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><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: #666666; font-style: italic;">// functions.php</span><br />
<span style="color: #000000; font-weight: bold;">function</span> add_login_logout_link<span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000088;">$newposition</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #666666; font-style: italic;">// split the menu items into an array using the ending &lt;li&gt; tag</span><br />
&nbsp; <span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">,</span><span style="color: #000088;">$items</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// setup our new link (without the end li tag)</span><br />
&nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_user_logged_in<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$newlink</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;li&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$args</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">before</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;a title=&quot;Logout&quot; href=&quot;'</span><span style="color: #339933;">.</span> wp_logout_url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index.php'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$args</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link_before</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'Logout'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$args</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link_after</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$args</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">after</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// no &lt;/li&gt; needed this is added later</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000088;">$newlink</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;li&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$args</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">before</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;a title=&quot;Login&quot; href=&quot;'</span><span style="color: #339933;">.</span> wp_login_url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index.php'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$args</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link_before</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'Login'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$args</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link_after</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$args</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">after</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// no &lt;/li&gt; needed this is added later</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #000088;">$newitems</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// loop through the menu items, and add the new link at the right position</span><br />
&nbsp; <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$items</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$index</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// array indexes are always one less than the position (1st item is index 0)</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$index</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$newposition</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000088;">$newitems</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$newlink</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$newitems</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// finally put all the menu items back together into a string using the ending &lt;li&gt; tag and return</span><br />
&nbsp; <span style="color: #000088;">$newitems</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/implode"><span style="color: #990000;">implode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">,</span><span style="color: #000088;">$newitems</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$newitems</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;">'wp_nav_menu_items'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'add_login_logout_link'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Note that in the above example, I have also used the <kbd>before</kbd>, <kbd>after</kbd>, <kbd>before_link</kbd> and <kbd>after_link</kbd> args values so that the additional link has the same display properties as the generated ones. Also the <kbd>add_filter</kbd> function takes 4 arguments: the &#8220;hook&#8221; or point in the code where this code should be executed, the function to be carried out, the priority (1 is executed first, 12 is executed last) and the number of arguments the function accepts. Using priority 10 means the code is executed near last.</p>
<p class="small"><strong>A Note on Snippets:</strong> When customising a CMS such as WordPress it is often the simplest pieces of code which are the hardest to either find or remember. These snippets are placed here for my own reference and will hopefully be useful to others. If you find them useful or have any suggestions, please let me know.</p>


<p>Related posts:<ol><li><a href='http://erisds.co.uk/wordpress/snippet-wordpress-customise-the-excerpt-length-and-more-string' rel='bookmark' title='Permanent Link: Snippet: WordPress &#8211; Customise the Excerpt Length and More string'>Snippet: WordPress &#8211; Customise the Excerpt Length and More string</a><small>These functions and hooks let you customise the output of...</small></li>
<li><a href='http://erisds.co.uk/wordpress/spotlight-wordpress-admin-menu-remove-add-new-pages-or-posts-link' rel='bookmark' title='Permanent Link: Spotlight: WordPress Admin Menu &#8211; Remove &#8220;Add New&#8221; pages or posts link'>Spotlight: WordPress Admin Menu &#8211; Remove &#8220;Add New&#8221; pages or posts link</a><small>Back in June I posted about tidying up the WordPress...</small></li>
<li><a href='http://erisds.co.uk/wordpress/snippet-wordpress-admin-tidy-dashboard-widgets-by-role' rel='bookmark' title='Permanent Link: Snippet: WordPress Admin &#8211; Tidy Dashboard Widgets By Role'>Snippet: WordPress Admin &#8211; Tidy Dashboard Widgets By Role</a><small>Recently I worked on a Wordpress site where I wanted...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://erisds.co.uk/wordpress/snippet-wordpress-3-0-menus-add-a-login-logout-link/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Spotlight: WordPress Admin Menu &#8211; Remove &#8220;Add New&#8221; pages or posts link</title>
		<link>http://erisds.co.uk/wordpress/spotlight-wordpress-admin-menu-remove-add-new-pages-or-posts-link</link>
		<comments>http://erisds.co.uk/wordpress/spotlight-wordpress-admin-menu-remove-add-new-pages-or-posts-link#comments</comments>
		<pubDate>Mon, 30 Aug 2010 16:37:34 +0000</pubDate>
		<dc:creator>ErisDS</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[featured]]></category>
		<category><![CDATA[menus]]></category>
		<category><![CDATA[spotlight]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://erisds.co.uk/?p=1544</guid>
		<description><![CDATA[<img src="http://erisds.co.uk/wp-content/uploads/2010/08/wordpress_pages_menu3.png" alt="WordPress Pages Menu" title="wordpress_pages_menu3" width="154" height="201" class="alignleft size-full wp-image-1592" />Back in June I posted about <a title="Snippet: WordPress Admin - tidy dashboard widgets by role" href="http://erisds.co.uk/wordpress/snippet-wordpress-admin-tidy-dashboard-widgets-by-role">tidying up the WordPress admin dashboard</a>. Recently I got a comment on that article asking if the admin menu could be altered for different users in a similar way. This turned out to be ever-so-slightly more complicated that I expected because there is no way to distinguish between the permission to edit and the permission to add a page or post. However, like most things in WordPress with a bit of graft it's usually possible!

<strong>Code Example:</strong> You can download the complete code sample with comments right here: <a href='http://erisds.co.uk/wp-content/uploads/2010/08/functions.zip'>functions.php [ZIP File]</a>


Related posts:<ol><li><a href='http://erisds.co.uk/wordpress/snippet-wordpress-admin-tidy-dashboard-widgets-by-role' rel='bookmark' title='Permanent Link: Snippet: WordPress Admin &#8211; Tidy Dashboard Widgets By Role'>Snippet: WordPress Admin &#8211; Tidy Dashboard Widgets By Role</a><small>Recently I worked on a Wordpress site where I wanted...</small></li>
<li><a href='http://erisds.co.uk/wordpress/snippet-wordpress-3-0-menus-add-a-login-logout-link' rel='bookmark' title='Permanent Link: Snippet: WordPress 3.0 Menus &#8211; Add a login / logout link'>Snippet: WordPress 3.0 Menus &#8211; Add a login / logout link</a><small>The new WordPress 3.0 menu system is pretty powerful and...</small></li>
<li><a href='http://erisds.co.uk/wordpress/spotlight-wordpress-pods-plugin' rel='bookmark' title='Permanent Link: Spotlight: WordPress Pods Plugin'>Spotlight: WordPress Pods Plugin</a><small>Have you ever needed to build a website which fit...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Back in June I posted about <a title="Snippet: WordPress Admin - tidy dashboard widgets by role" href="http://erisds.co.uk/wordpress/snippet-wordpress-admin-tidy-dashboard-widgets-by-role">tidying up the WordPress admin dashboard</a>. Recently I got a comment on that article asking if the admin menu could be altered for different users in a similar way. </p>
<p>Here&#8217;s the question:</p>
<blockquote><p>Can I lose the “add new” under Pages drop down for editors? I don’t want them to have the ability to create new pages.</p></blockquote>
<p>I&#8217;ve played with the WordPress admin menu a bit before now. There are two global variables which allow you to add (although there are <a href="http://codex.wordpress.org/Adding_Administration_Menus" title="WP Codex: Adding Administration Menus">much better ways</a> to do this) and more importantly remove items from the WordPress menu. These variables are <kbd>$menu</kbd> for top-level menu groups like &#8220;Posts&#8221;, &#8220;Media&#8221; and <kbd>$submenu</kbd> for managing the sub-level items like &#8220;Add New&#8221; or &#8220;Library&#8221;. </p>
<p><img src="http://erisds.co.uk/wp-content/uploads/2010/08/wordpress_pages_menu2.png" alt="WordPress Pages Menus" title="wordpress_pages_menu2" width="154" height="201" class="alignleft size-full wp-image-1559" />In this case, we only want to remove the &#8220;Add New&#8221; sub-menu item from the pages menu, so we only need to use <kbd>$submenu</kbd>. If you use <kbd>var_dump</kbd> or <kbd>print_r</kbd> to display the contents of <kbd>$submenu</kbd> you&#8217;ll see the part of the array for the &#8220;Pages&#8221; menu looks like the snippet below. It contains two entries: one for the &#8220;Pages&#8221; listing which allows you to edit pages, and one for the &#8220;Add New&#8221; link that we want to remove. Also note: for each sub-menu item there are three pieces of information: The text to show, the capability the user must have to see this link, and the relative URL for the menu item.</p>
<p class="small"><strong>*Please note:</strong> all of the following will also work for posts. You will need to substitute the word &#8220;page(s)&#8221; for &#8220;post(s)&#8221; and follow the additional instructions. For other parts of the WordPress admin you&#8217;ll need to find the right URLs, sub menu items and capabilities. All code should be placed in your theme&#8217;s functions.php file. Full code example is here:  <a href='http://erisds.co.uk/wp-content/uploads/2010/08/functions.zip' onClick="_gaq.push(['_trackPageview', '/downloads/remove_add_new_link001']);">functions.php [ZIP File]</a></p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// $submenu array...</span><br />
&nbsp;<span style="color: #0000ff;">'edit.php?post_type=page'</span> <span style="color: #339933;">=&gt;</span> <br />
&nbsp; &nbsp; <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><br />
&nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">5</span> <span style="color: #339933;">=&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">0</span> <span style="color: #339933;">=&gt;</span> string <span style="color: #0000ff;">'Pages'</span> <span style="color: #009900;">&#40;</span>length<span style="color: #339933;">=</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> string <span style="color: #0000ff;">'edit_pages'</span> <span style="color: #009900;">&#40;</span>length<span style="color: #339933;">=</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">2</span> <span style="color: #339933;">=&gt;</span> string <span style="color: #0000ff;">'edit.php?post_type=page'</span> <span style="color: #009900;">&#40;</span>length<span style="color: #339933;">=</span><span style="color: #cc66cc;">23</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">10</span> <span style="color: #339933;">=&gt;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">0</span> <span style="color: #339933;">=&gt;</span> string <span style="color: #0000ff;">'Add New'</span> <span style="color: #009900;">&#40;</span>length<span style="color: #339933;">=</span><span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> string <span style="color: #0000ff;">'publish_pages'</span> <span style="color: #009900;">&#40;</span>length<span style="color: #339933;">=</span><span style="color: #cc66cc;">13</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #cc66cc;">2</span> <span style="color: #339933;">=&gt;</span> string <span style="color: #0000ff;">'post-new.php?post_type=page'</span> <span style="color: #009900;">&#40;</span>length<span style="color: #339933;">=</span><span style="color: #cc66cc;">27</span><span style="color: #009900;">&#41;</span></div></div>
<p>With all this in mind, the simplest way to remove the &#8220;Add New&#8221; link from the pages menu, is to unset this part of the array before the menu is drawn. We can create a function to do this in the functions.php file, first declaring the <kbd>$submenu</kbd> global variable and then unsetting the bit that we don&#8217;t want. Finally we need to add our function to the <kbd>admin_menu</kbd> action hook so that it is called at the right time.</p>
<div class="codecolorer-container php twitlight" 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 /></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: #666666; font-style: italic;">// functions.php</span><br />
<span style="color: #000000; font-weight: bold;">function</span> modify_menu<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$submenu</span><span style="color: #339933;">;</span><br />
&nbsp; <a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$submenu</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'edit.php?post_type=page'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// for posts it should be: </span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// unset($submenu['edit.php'][10]);</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #666666; font-style: italic;">// call the function to modify the menu when the admin menu is drawn</span><br />
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_menu'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'modify_menu'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>At first glance we&#8217;ve now achieved what we set out to do &#8211; the &#8220;Add New&#8221; link is removed from the menu, however this doesn&#8217;t really solve the underlying problem. The url for adding a new page is <kbd>post-new.php?post_type=page</kbd> and because we haven&#8217;t changed the permissions of an editor they can still access the page. Furthermore, there is also an &#8220;Add New&#8221; link at the top of &#8220;Pages&#8221; list page &#8211; so they can also still find the page easily.</p>
<p>So what we really need to do, is change the capabilities of the &#8220;editor&#8221; role. In WordPress each role has a set of &#8220;capabilities&#8221; or permissions &#8211; things they are allowed to do. The capability that allows someone with the &#8220;editor&#8221; role to access the Add New Page screen is &#8220;edit_page&#8221;, however if we remove this capability we will lose the whole &#8220;Pages&#8221; menu and also stop them being able to edit pages. </p>
<p>There is no way to use capabilities to restrict access to the Add New Page screen without also restricting access to the Pages list &#038; Edit page screen. However, we can stop people from being able to publish pages using the &#8220;publish_pages&#8221; capability &#8211; this means they can create pages but they won&#8217;t appear on the website. Although this isn&#8217;t a perfect solution, it seems like a good start.</p>
<div class="codecolorer-container php twitlight" 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 /></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: #666666; font-style: italic;">// functions.php</span><br />
<span style="color: #000000; font-weight: bold;">function</span> modify_capabilities<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// get the role you want to change: editor, author, contributor, subscriber</span><br />
&nbsp; <span style="color: #000088;">$editor_role</span> <span style="color: #339933;">=</span> get_role<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'editor'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000088;">$editor_role</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">remove_cap</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'publish_pages'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #666666; font-style: italic;">// for posts it should be:</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// $editor_role-&gt;remove_cap('publish_posts');</span><br />
&nbsp; <br />
&nbsp; <span style="color: #666666; font-style: italic;">// to add capabilities use add_cap()</span><br />
<span style="color: #009900;">&#125;</span><br />
<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;">'modify_capabilities'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>The above snippet shows a function which gets the &#8220;editor&#8221; role and removes the &#8220;publish_pages&#8221; capability. This is hooked into &#8220;admin_init&#8221; so that it is run on each admin page. Now when editors go to the Add New Page screen they will only be able to &#8220;Submit for review&#8221; not publish the page. So now we know how to both actually stop users from creating pages AND remove the sub-menu item. </p>
<p>Now that we&#8217;re working with capabilities, we can change our <kbd>modify_menu</kbd> function to do the same. Instead of completely unsetting the menu item, we can set the capability so that it only works if the user has the capability &#8220;publish_pages&#8221;. This is just a slightly nicer way to hide the menu item &#8211; you could grant one specific editor user the &#8220;publish_pages&#8221; capability and they would still be able to access the menu item.</p>
<div class="codecolorer-container php twitlight" 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: #666666; font-style: italic;">// functions.php</span><br />
<span style="color: #000000; font-weight: bold;">function</span> modify_menu<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$submenu</span><span style="color: #339933;">;</span><br />
<span style="display:block;background-color:#ffff66">&nbsp; <span style="color: #000088;">$submenu</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'edit.php?post_type=page'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'publish_pages'</span><span style="color: #339933;">;</span><br /></span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// for posts it should be:</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// $submenu['edit.php'][10][1] = 'publish_posts';</span><br />
<span style="color: #009900;">&#125;</span><br />
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_menu'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'modify_menu'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Next let&#8217;s get rid of that pesky &#8220;Add New&#8221; button on the Pages list screen. There doesn&#8217;t seem to be a hook we can use to do this, so instead I&#8217;ve used good ol&#8217; fashioned CSS. We check if we are on the &#8220;edit-page&#8221; screen using the <kbd>$current_screen</kbd> global variable and if the user has the &#8220;publish_pages&#8221; capability using the <kbd>current_user_can</kbd> method. Then we spit out some CSS to hide the button and hook this into admin_head to the CSS is output in a sensible place.</p>
<div class="codecolorer-container php twitlight" 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 /></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: #666666; font-style: italic;">// functions.php</span><br />
<span style="color: #000000; font-weight: bold;">function</span> hide_buttons<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$current_screen</span><span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$current_screen</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'edit-page'</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>current_user_can<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'publish_pages'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;style&gt;.add-new-h2{display: none;}&lt;/style&gt;'</span><span style="color: #339933;">;</span> &nbsp;<br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #666666; font-style: italic;">// for posts the if statement would be:</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// if($current_screen-&gt;id == 'edit-post' &amp;&amp; !current_user_can('publish_posts'))</span><br />
<span style="color: #009900;">&#125;</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;">'hide_buttons'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Now we have editors which cannot see the &#8220;Add New&#8221; link in the Pages menu, or the button on the Pages screen, so there&#8217;s no easy way for them to get there. Even if they are clever enough to figure out the URL they won&#8217;t actually be able to publish their pages. However if we want to go the whole hog, we can add a bit more code to redirect them from the Add New Page screen and show them an error message.</p>
<div class="codecolorer-container php twitlight" 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 /></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: #666666; font-style: italic;">// functions.php</span><br />
<span style="color: #000000; font-weight: bold;">function</span> permissions_admin_redirect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/stripos"><span style="color: #990000;">stripos</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post-new.php?post_type=page'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #666666; font-style: italic;">// for posts result should be: &nbsp;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// $result = stripos($_SERVER['REQUEST_URI'], 'post-new.php');</span><br />
&nbsp; <br />
&nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">!==</span><span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>current_user_can<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'publish_pages'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; wp_redirect<span style="color: #009900;">&#40;</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'siteurl'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/wp-admin/index.php?permissions_error=true'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #666666; font-style: italic;">// for posts the if statement should be:</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// if ($result!==false &amp;&amp; !current_user_can('publish_posts')) {</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_menu'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'permissions_admin_redirect'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>The above is an additional function to test the current request URI. If it matches the Add New Page screen AND the user doesn&#8217;t have the &#8220;publish_page&#8221; capability we redirect them to the admin dashboard. The dashboard URL is <kbd>/wp-admin/index.php</kbd>, but I&#8217;ve added <kbd>permissions_error=true</kbd> so that WordPress will know to show an error message.</p>
<div class="codecolorer-container php twitlight" 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 /></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: #666666; font-style: italic;">// functions.php</span><br />
<span style="color: #000000; font-weight: bold;">function</span> permissions_admin_notice<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// use the class &quot;error&quot; for red notices, and &quot;update&quot; for yellow notices</span><br />
&nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;div id='permissions-warning' class='error fade'&gt;&lt;p&gt;&lt;strong&gt;&quot;</span><span style="color: #339933;">.</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'You do not have permission to access that page.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/strong&gt;&lt;/p&gt;&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> permissions_show_notice<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'permissions_error'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_notices'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'permissions_admin_notice'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp;<br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</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;">'permissions_show_notice'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Finally, two more functions and one more action hook. The first to draw an error message / warning to the user, and the second which checks the &#8220;permissions_error&#8221; parameter and shows the error message if it is set. Now there is absolutely no way for an editor to get to the Add New Page screen, instead they will be redirected to the dashboard and shown an error.</p>
<p>So this all turned out to be ever-so-slightly more complicated that I expected because there is no way to distinguish between the permission to edit and the permission to add a page or post. However, like most things in WordPress with a bit of graft it&#8217;s usually possible! I hope this has been useful, if you got lost or  something doesn&#8217;t make sense or you know of a better way to do this <em>please</em> let me know via the comments.</p>
<p><strong>Code Example:</strong> All code should go into your theme&#8217;s functions.php file. You can download the complete code sample with comments right here: <a href='http://erisds.co.uk/wp-content/uploads/2010/08/functions.zip' onClick="_gaq.push(['_trackPageview', '/downloads/remove_add_new_link001']);">functions.php [ZIP File]</a></p>
<h3>Resources</h3>
<ul>
<li><a href="http://codex.wordpress.org/Adding_Administration_Menus" title="WP Codex: Adding Administration Menus">Adding administration menus</a></li>
<li><a href="http://hungred.com/how-to/remove-wordpress-admin-menu-affecting-wordpress-core-system/" title="Remove WordPress Admin Menu Without Affecting WordPress Core System">Remove WordPress Admin Menu Without Affecting WordPress Core System</a></li>
</ul>


<p>Related posts:<ol><li><a href='http://erisds.co.uk/wordpress/snippet-wordpress-admin-tidy-dashboard-widgets-by-role' rel='bookmark' title='Permanent Link: Snippet: WordPress Admin &#8211; Tidy Dashboard Widgets By Role'>Snippet: WordPress Admin &#8211; Tidy Dashboard Widgets By Role</a><small>Recently I worked on a Wordpress site where I wanted...</small></li>
<li><a href='http://erisds.co.uk/wordpress/snippet-wordpress-3-0-menus-add-a-login-logout-link' rel='bookmark' title='Permanent Link: Snippet: WordPress 3.0 Menus &#8211; Add a login / logout link'>Snippet: WordPress 3.0 Menus &#8211; Add a login / logout link</a><small>The new WordPress 3.0 menu system is pretty powerful and...</small></li>
<li><a href='http://erisds.co.uk/wordpress/spotlight-wordpress-pods-plugin' rel='bookmark' title='Permanent Link: Spotlight: WordPress Pods Plugin'>Spotlight: WordPress Pods Plugin</a><small>Have you ever needed to build a website which fit...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://erisds.co.uk/wordpress/spotlight-wordpress-admin-menu-remove-add-new-pages-or-posts-link/feed</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Upgrading old WordPress installs &#8211; not as scary as you think!</title>
		<link>http://erisds.co.uk/wordpress/upgrading-old-wordpress-installs-not-as-scary-as-you-think</link>
		<comments>http://erisds.co.uk/wordpress/upgrading-old-wordpress-installs-not-as-scary-as-you-think#comments</comments>
		<pubDate>Fri, 02 Jul 2010 12:27:38 +0000</pubDate>
		<dc:creator>ErisDS</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://erisds.co.uk/?p=1380</guid>
		<description><![CDATA[<img src="http://erisds.co.uk/wp-content/uploads/2010/07/wordpress-logo-notext-rgb-150x150.png" alt="" title="WordPress logo" width="150" height="150" class="alignleft size-thumbnail wp-image-1389" />Earlier this week I received an email requesting some help with a WordPress install that had been hacked. The site was almost 3 years old and was still running WordPress 2.2. It was quite funny getting to see and play with retro WordPress again, but it had to go.


Related posts:<ol><li><a href='http://erisds.co.uk/wordpress/wordpress-automatic-upgrades-one-of-the-pitfalls' rel='bookmark' title='Permanent Link: WordPress Automatic Upgrades &#8211; One of the pitfalls'>WordPress Automatic Upgrades &#8211; One of the pitfalls</a><small>This morning I woke up to announcements of a security...</small></li>
<li><a href='http://erisds.co.uk/wordpress/migrate-announcement' rel='bookmark' title='Permanent Link: WordPress: Migrate! Easy WordPress Site Migration'>WordPress: Migrate! Easy WordPress Site Migration</a><small>If you work with multiple environments (development, staging, production etc)...</small></li>
<li><a href='http://erisds.co.uk/wordpress/wordpress-2-8' rel='bookmark' title='Permanent Link: WordPress 2.8'>WordPress 2.8</a><small>Over the weekend I updated my blog to Wordpress 2.8....</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><img src="http://erisds.co.uk/wp-content/uploads/2010/07/wordpress-logo-notext-rgb-300x300.png" alt="" title="WordPress logo" width="300" height="300" class="alignleft size-medium wp-image-1389" />Earlier this week I received an email requesting some help with a WordPress install that had been hacked. The site was almost 3 years old and was still running WordPress 2.2. It was quite funny getting to see and play with retro WordPress again, but it had to go.</p>
<p>First of all I got rid of the hack. I didn&#8217;t do much research into WP2.2 security holes or spend any time trying to work out how it was done, I ran a text search on the files for the text and links that had been injected into the page and quickly discovered some superfluous functions in the theme footer and some other files. Deleting these got rid of the problem and restored the site to normal.</p>
<p>To be honest, I was nervous about upgrading this blog from WordPress 2.9.2 to 3.0, the software is moving on so quickly now, so the concept of upgrading from 2.2 where there isn&#8217;t even the luxury of an upgrade button filled me with dread. I did a little research into upgrading, and put out a <a href="http://twitter.com/ErisDS/status/17333044663" title="ErisDS on twitter - upgrading WordPress 2.2">feeler tweet</a> to see if anyone had experience useful tips. Someone suggested that I upgrade to 2.8 first then 2.9 and 3.0 but I decided to just go for it to start with.</p>
<h2>Upgrading WordPress</h2>
<p>The <a href="http://codex.wordpress.org/Upgrading_WordPress_Extended#Detailed_Upgrade_Instructions_for_1.5.x.2C_and_versions_2.0_-_2.6.5.2C_to_3.0">WordPress documentation has extensive information on upgrading </a>WordPress.</p>
<p>In short, the steps involve:</p>
<ol>
<li>Backing up all your files and database</li>
<li>Deactivating all plugins</li>
<li>Deleting your WordPress install except for the customised parts (wp-config.php, .htaccess, themes, plugins, uploads, images, and any language files)</li>
<li>Downloading the <a href="http://wordpress.org/download/">latest version of WordPress</a> and unpacking.</li>
<li>Uploading the new WordPress files to your website</li>
<li>Going to wp-admin and following the instructions to run the upgrade script</li>
</ol>
<p>The <a href="http://codex.wordpress.org/Upgrading_WordPress_Extended#Detailed_Upgrade_Instructions_for_1.5.x.2C_and_versions_2.0_-_2.6.5.2C_to_3.0">WordPress upgrade documentation</a> goes into great detail, so I highly recommend you follow it word for word. I was very careful to follow the instructions carefully, and I&#8217;m pleased to report that the upgrade was a complete success. Not a bug, not a snag, not a hitch &#8211; easy peasy!</p>
<h2>My Top Tips</h2>
<p>Some additional things I recommend doing are:</p>
<ul>
<li>Be absolutely sure to deactivate all your plugins before deleting files and starting the upgrade process</li>
<li>Once the upgrade process has run, check your website thoroughly before reactivating or upgrading any plugins</li>
<li>If all is OK, take another backup of the database and files at this point</li>
<li>After backing up, reactivate each plugin one-by-one testing the site thoroughly after each reactivation to ensure no bugs are caused and that the plugin provides the expected functionality.</li>
<li>Take note of any plugins which malfunction, see if there is an available upgrade (don&#8217;t run it yet) and deactivate the plugin until you have tested them all</li>
<li>Backup again! You&#8217;ve now got all the working plugins enabled and the site is almost back to normal&#8230; so backup before upgrading your plugins!</li>
<li>Upgrade each plugin one-by-one (and reactivate if necessary), again testing after each upgrade.</li>
<li>You may have to find new plugins to replace old ones which are no longer maintained, but with luck your site should now be back to normal.</li>
</ul>


<p>Related posts:<ol><li><a href='http://erisds.co.uk/wordpress/wordpress-automatic-upgrades-one-of-the-pitfalls' rel='bookmark' title='Permanent Link: WordPress Automatic Upgrades &#8211; One of the pitfalls'>WordPress Automatic Upgrades &#8211; One of the pitfalls</a><small>This morning I woke up to announcements of a security...</small></li>
<li><a href='http://erisds.co.uk/wordpress/migrate-announcement' rel='bookmark' title='Permanent Link: WordPress: Migrate! Easy WordPress Site Migration'>WordPress: Migrate! Easy WordPress Site Migration</a><small>If you work with multiple environments (development, staging, production etc)...</small></li>
<li><a href='http://erisds.co.uk/wordpress/wordpress-2-8' rel='bookmark' title='Permanent Link: WordPress 2.8'>WordPress 2.8</a><small>Over the weekend I updated my blog to Wordpress 2.8....</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://erisds.co.uk/wordpress/upgrading-old-wordpress-installs-not-as-scary-as-you-think/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Snippet: WordPress Admin &#8211; Tidy Dashboard Widgets By Role</title>
		<link>http://erisds.co.uk/wordpress/snippet-wordpress-admin-tidy-dashboard-widgets-by-role</link>
		<comments>http://erisds.co.uk/wordpress/snippet-wordpress-admin-tidy-dashboard-widgets-by-role#comments</comments>
		<pubDate>Wed, 30 Jun 2010 11:30:56 +0000</pubDate>
		<dc:creator>ErisDS</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[widgets]]></category>

		<guid isPermaLink="false">http://erisds.co.uk/?p=924</guid>
		<description><![CDATA[Recently I worked on a Wordpress site where I wanted to be able to customise the dashboard for different user roles. Wordpress by default has administrators, editors, authors, contributors and subscribers. It's not too much to assume you might not want to show your editors or authors all the details of your blog posts etc and this short snippet will allow you to do just that.



Related posts:<ol><li><a href='http://erisds.co.uk/wordpress/spotlight-wordpress-admin-menu-remove-add-new-pages-or-posts-link' rel='bookmark' title='Permanent Link: Spotlight: WordPress Admin Menu &#8211; Remove &#8220;Add New&#8221; pages or posts link'>Spotlight: WordPress Admin Menu &#8211; Remove &#8220;Add New&#8221; pages or posts link</a><small>Back in June I posted about tidying up the WordPress...</small></li>
<li><a href='http://erisds.co.uk/wordpress/snippet-wordpress-3-0-menus-add-a-login-logout-link' rel='bookmark' title='Permanent Link: Snippet: WordPress 3.0 Menus &#8211; Add a login / logout link'>Snippet: WordPress 3.0 Menus &#8211; Add a login / logout link</a><small>The new WordPress 3.0 menu system is pretty powerful and...</small></li>
<li><a href='http://erisds.co.uk/wordpress/snippet-wordpress-customise-the-excerpt-length-and-more-string' rel='bookmark' title='Permanent Link: Snippet: WordPress &#8211; Customise the Excerpt Length and More string'>Snippet: WordPress &#8211; Customise the Excerpt Length and More string</a><small>These functions and hooks let you customise the output of...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Recently I worked on a WordPress site where I wanted to be able to customise the dashboard for different user roles. <a href="http://codex.wordpress.org/Roles_and_Capabilities">WordPress has the default roles</a> of administrators, editors, authors, contributors and subscribers. It&#8217;s not too much to assume you might not want to show your editors or authors all the details of your blog posts etc and placing these short code snippets into your theme&#8217;s <kbd>functions.php</kbd> file will allow you to do just that.</p>
<h2>Clearing up</h2>
<p>Lets get rid of the incoming links widget for authors and editors and then clean up some of the other boxes for everyone:</p>
<div class="codecolorer-container php twitlight" 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;">function</span> tidy_dashboard<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp_meta_boxes</span><span style="color: #339933;">,</span> <span style="color: #000088;">$current_user</span><span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #666666; font-style: italic;">// remove incoming links info for authors or editors</span><br />
&nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/in_array"><span style="color: #990000;">in_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'author'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$current_user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">roles</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <a href="http://www.php.net/in_array"><span style="color: #990000;">in_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'editor'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$current_user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">roles</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wp_meta_boxes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'normal '</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'core'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard_incoming_links'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; <span style="color: #666666; font-style: italic;">// remove the plugins info and news feeds for everyone</span><br />
&nbsp; <a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wp_meta_boxes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'normal'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'core'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard_plugins'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wp_meta_boxes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'side'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'core'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard_primary'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wp_meta_boxes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'side'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'core'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard_secondary'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #666666; font-style: italic;">//add our function to the dashboard setup hook</span><br />
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_dashboard_setup'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'tidy_dashboard'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>Here&#8217;s a full list of how to unset each of the current default dashboard widgets:</p>
<div class="codecolorer-container php twitlight" 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 /></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: #666666; font-style: italic;">//Right Now - Comments, Posts, Pages at a glance</span><br />
<a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wp_meta_boxes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'normal'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'core'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard_right_now'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">//Recent Comments</span><br />
<a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wp_meta_boxes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'normal'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'core'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard_recent_comments'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">//Incoming Links</span><br />
<a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wp_meta_boxes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'normal'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'core'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard_incoming_links'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">//Plugins - Popular, New and Recently updated Wordpress Plugins</span><br />
<a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wp_meta_boxes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'normal'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'core'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard_plugins'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">//Wordpress Development Blog Feed</span><br />
<a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wp_meta_boxes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'side'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'core'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard_primary'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">//Other Wordpress News Feed</span><br />
<a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wp_meta_boxes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'side'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'core'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard_secondary'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">//Quick Press Form</span><br />
<a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wp_meta_boxes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'side'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'core'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard_quick_press'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #666666; font-style: italic;">//Recent Drafts List</span><br />
<a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wp_meta_boxes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'side'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'core'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard_recent_drafts'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<h2>Add your own &#8211; Private pages menu</h2>
<p>Perhaps rather than the default information, you have other items you&#8217;d like to be on the dashboard for authors or editors etc? I often add a dashboard widget to list private pages. Here&#8217;s how:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><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 /></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: #666666; font-style: italic;">// function to display widget</span><br />
<span style="color: #000000; font-weight: bold;">function</span> display_dashboard_widget<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">//define arguments for WP_Query()</span><br />
&nbsp; <span style="color: #000088;">$qargs</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'post_type'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'page'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">'post_status'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'private'</span><br />
&nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// perform the query</span><br />
&nbsp; <span style="color: #000088;">$q</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WP_Query<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000088;">$q</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$qargs</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// setup the content with a list</span><br />
&nbsp; <span style="color: #000088;">$widget_content</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;ul&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #666666; font-style: italic;">// execute the WP loop</span><br />
&nbsp; <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">have_posts</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$q</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">the_post</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #000088;">$widget_content</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;li&gt;&lt;a href=&quot;'</span><span style="color: #339933;">.</span>get_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; rel=&quot;bookmark&quot;&gt;'</span><span style="color: #339933;">.</span> get_the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt;&lt;/li&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #000088;">$widget_content</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/ul&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #666666; font-style: italic;">// return the content you want displayed</span><br />
&nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$widget_content</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <br />
<br />
<span style="color: #666666; font-style: italic;">//function to setup widget</span><br />
<span style="color: #000000; font-weight: bold;">function</span> add_dashboard_widgets<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// create a dashboard widget called &quot;private_page_menu_dashboard_widget&quot; with the title &quot;Private Pages Menu&quot; and call our display function to draw it</span><br />
&nbsp; wp_add_dashboard_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'private_page_menu_dashboard_widget'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Private Pages Menu'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'display_dashboard_widget'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span> <br />
<br />
<span style="color: #666666; font-style: italic;">// finally we have to hook our function into the dashboard setup using add_action</span><br />
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_dashboard_setup'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'add_dashboard_widgets'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>The only problem with <kbd>wp_add_dashboard_widget</kbd> is that it doesn&#8217;t allow you to define where on the dashboard the widget is placed. Instead it just places the box at the bottom of the left hand side in the <kbd>['normal']['core']</kbd> array.</p>
<p>I want my private page menu to display at the top on the right hand side of the dashboard, so I am going to add a few more lines to <kbd>add_dashboard_widgets()</kbd> to shuffle the boxes around the way I want them. This will be overridden by user settings if the boxes are dragged around, but insures that my authors and editors see the box in an obvious position when they first login.</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><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 /></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> add_dashboard_widgets<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// don't forget the global to get all dashboard widgets</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp_meta_boxes</span><span style="color: #339933;">;</span><br />
&nbsp;<br />
&nbsp; <span style="color: #666666; font-style: italic;">// create a dashboard widget called &quot;private_page_menu_dashboard_widget&quot; with the title &quot;Private Pages Menu&quot; and call our display function to draw it</span><br />
&nbsp; wp_add_dashboard_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'private_page_menu_dashboard_widget'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Private Pages Menu'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'display_dashboard_widget'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// reorder the boxes - first save the left and right columns into variables</span><br />
&nbsp; <span style="color: #000088;">$left_dashboard</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wp_meta_boxes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'normal'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'core'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000088;">$right_dashboard</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wp_meta_boxes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'side'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'core'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// take a copy of the new widget from the left column </span><br />
&nbsp; <span style="color: #000088;">$my_widget</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'private_page_menu_dashboard_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$left_dashboard</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'private_page_menu_dashboard_widget'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <br />
&nbsp; <span style="color: #666666; font-style: italic;">// remove the new widget from the left column</span><br />
&nbsp; <a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$left_dashboard</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'private_page_menu_dashboard_widget'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// use array_merge so that the new widget is pushed on to the beginning of the right column's array &nbsp;</span><br />
&nbsp; <span style="color: #000088;">$right_dashboard</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array_merge"><span style="color: #990000;">array_merge</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$my_widget</span><span style="color: #339933;">,</span> <span style="color: #000088;">$right_dashboard</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// finally replace the left and right columns with the new reordered versions</span><br />
&nbsp; <span style="color: #000088;">$wp_meta_boxes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'normal'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'core'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$left_dashboard</span><span style="color: #339933;">;</span>&nbsp; <br />
&nbsp; <span style="color: #000088;">$wp_meta_boxes</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dashboard'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'side'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'core'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$right_dashboard</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>I hope you find these tricks as useful as I do!</p>
<h3>Resources</h3>
<ul>
<li><a href="http://www.smashingmagazine.com/2009/12/14/advanced-power-tips-for-wordpress-template-developers-reloaded/">Power Tips for WordPress Template Developers: Reloaded</a> &#8211; more cool back end optimisations, hacks and tweaks</li>
<li><a href="http://wordpress.org/extend/plugins/register-plus/">Register Plus WordPress Plugin</a> &#8211; customise your registration, login and admin areas</li>
<li><a href="http://codex.wordpress.org/Dashboard_Widgets_API">Dashboard Widgets API</a> &#8211; more info on adding and removing dashboard widgets</li>
</ul>
<p class="small"><strong>A Note on Snippets:</strong> When customising a CMS such as WordPress it is often the simplest pieces of code which are the hardest to either find or remember. These snippets are placed here for my own reference and will hopefully be useful to others. If you find them useful or have any suggestions, please let me know.</p>


<p>Related posts:<ol><li><a href='http://erisds.co.uk/wordpress/spotlight-wordpress-admin-menu-remove-add-new-pages-or-posts-link' rel='bookmark' title='Permanent Link: Spotlight: WordPress Admin Menu &#8211; Remove &#8220;Add New&#8221; pages or posts link'>Spotlight: WordPress Admin Menu &#8211; Remove &#8220;Add New&#8221; pages or posts link</a><small>Back in June I posted about tidying up the WordPress...</small></li>
<li><a href='http://erisds.co.uk/wordpress/snippet-wordpress-3-0-menus-add-a-login-logout-link' rel='bookmark' title='Permanent Link: Snippet: WordPress 3.0 Menus &#8211; Add a login / logout link'>Snippet: WordPress 3.0 Menus &#8211; Add a login / logout link</a><small>The new WordPress 3.0 menu system is pretty powerful and...</small></li>
<li><a href='http://erisds.co.uk/wordpress/snippet-wordpress-customise-the-excerpt-length-and-more-string' rel='bookmark' title='Permanent Link: Snippet: WordPress &#8211; Customise the Excerpt Length and More string'>Snippet: WordPress &#8211; Customise the Excerpt Length and More string</a><small>These functions and hooks let you customise the output of...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://erisds.co.uk/wordpress/snippet-wordpress-admin-tidy-dashboard-widgets-by-role/feed</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Snippet: WordPress &#8211; Customise the Excerpt Length and More string</title>
		<link>http://erisds.co.uk/wordpress/snippet-wordpress-customise-the-excerpt-length-and-more-string</link>
		<comments>http://erisds.co.uk/wordpress/snippet-wordpress-customise-the-excerpt-length-and-more-string#comments</comments>
		<pubDate>Fri, 15 Jan 2010 18:17:39 +0000</pubDate>
		<dc:creator>ErisDS</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://erisds.co.uk/?p=944</guid>
		<description><![CDATA[These functions and hooks let you customise the output of <kbd>the_excerpt()</kbd> template tag. Just copy and paste into the <kbd>functions.php</kbd> file in your theme. This works for both posts and pages.


Related posts:<ol><li><a href='http://erisds.co.uk/wordpress/snippet-wordpress-3-0-menus-add-a-login-logout-link' rel='bookmark' title='Permanent Link: Snippet: WordPress 3.0 Menus &#8211; Add a login / logout link'>Snippet: WordPress 3.0 Menus &#8211; Add a login / logout link</a><small>The new WordPress 3.0 menu system is pretty powerful and...</small></li>
<li><a href='http://erisds.co.uk/wordpress/snippet-wordpress-admin-tidy-dashboard-widgets-by-role' rel='bookmark' title='Permanent Link: Snippet: WordPress Admin &#8211; Tidy Dashboard Widgets By Role'>Snippet: WordPress Admin &#8211; Tidy Dashboard Widgets By Role</a><small>Recently I worked on a Wordpress site where I wanted...</small></li>
<li><a href='http://erisds.co.uk/wordpress/wordpress-link_before-and-link_after-dont-display-in-wp_list_pages' rel='bookmark' title='Permanent Link: WordPress: link_before and link_after don&#8217;t display in wp_list_pages'>WordPress: link_before and link_after don&#8217;t display in wp_list_pages</a><small>Have you ever stumbled across the issue where wp_list_pages isn't...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>These functions and hooks let you customise the output of <kbd>the_excerpt()</kbd> template tag. Just copy and paste into the <kbd>functions.php</kbd> file in your theme. This works for both posts and pages.</p>
<p>To change the excerpt length (how many words are output -<ins datetime="2010-06-25T12:38:24+00:00"> the default is 55 words</ins>) , define a function which returns the number you want and then call it with <kbd>add_filter()</kbd> on the &#8216;excerpt_length&#8217; filter as shown below.</p>
<div class="codecolorer-container php twitlight" 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 /></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> custom_excerpt_length<span style="color: #009900;">&#40;</span><span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
<span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">20</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;">'excerpt_length'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'custom_excerpt_length'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>By default excerpts which are generated by <strong>WordPress</strong> (as opposed to defined via the &#8220;Excerpt&#8221; box) have the string &#8220;[...]&#8221; You might want to turn this into a link to the post or page and/or change the dots to something like &#8220;more&#8221;. The code below does both of these things using <kbd>str_replace()</kbd>.</p>
<div class="codecolorer-container php twitlight" 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="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> custom_excerpt_more<span style="color: #009900;">&#40;</span><span style="color: #000088;">$more</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$post</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">return</span> <a href="http://www.php.net/str_replace"><span style="color: #990000;">str_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'[...]'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span><span style="color: #339933;">.</span>get_permalink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>ID<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;...read more...&lt;/a&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$more</span><span style="color: #009900;">&#41;</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;">'excerpt_more'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'custom_excerpt_more'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<p>You can change the second parameter of <kbd>str_replace()</kbd> to whatever you want to be displayed. I included the <kbd>$post</kbd> global so that I could get the permalink and make the string into a link to the post/page.</p>
<p>Please note these will not work if you have any plugin installed which removes the excerpt hooks. One such plugin is the <a href="http://wordpress.org/extend/plugins/event-calendar/">Event Calendar 3 plugin</a>. If you come across any more please let me know in the comments.</p>
<p class="small"><strong>A Note on Snippets:</strong> When customising a CMS such as WordPress it is often the simplest pieces of code which are the hardest to either find or remember. These snippets are placed here for my own reference and will hopefully be useful to others. If you find them useful or have any suggestions, please let me know.</p>


<p>Related posts:<ol><li><a href='http://erisds.co.uk/wordpress/snippet-wordpress-3-0-menus-add-a-login-logout-link' rel='bookmark' title='Permanent Link: Snippet: WordPress 3.0 Menus &#8211; Add a login / logout link'>Snippet: WordPress 3.0 Menus &#8211; Add a login / logout link</a><small>The new WordPress 3.0 menu system is pretty powerful and...</small></li>
<li><a href='http://erisds.co.uk/wordpress/snippet-wordpress-admin-tidy-dashboard-widgets-by-role' rel='bookmark' title='Permanent Link: Snippet: WordPress Admin &#8211; Tidy Dashboard Widgets By Role'>Snippet: WordPress Admin &#8211; Tidy Dashboard Widgets By Role</a><small>Recently I worked on a Wordpress site where I wanted...</small></li>
<li><a href='http://erisds.co.uk/wordpress/wordpress-link_before-and-link_after-dont-display-in-wp_list_pages' rel='bookmark' title='Permanent Link: WordPress: link_before and link_after don&#8217;t display in wp_list_pages'>WordPress: link_before and link_after don&#8217;t display in wp_list_pages</a><small>Have you ever stumbled across the issue where wp_list_pages isn't...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://erisds.co.uk/wordpress/snippet-wordpress-customise-the-excerpt-length-and-more-string/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Spotlight: WordPress Pods Plugin</title>
		<link>http://erisds.co.uk/wordpress/spotlight-wordpress-pods-plugin</link>
		<comments>http://erisds.co.uk/wordpress/spotlight-wordpress-pods-plugin#comments</comments>
		<pubDate>Sun, 28 Jun 2009 22:09:02 +0000</pubDate>
		<dc:creator>ErisDS</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[spotlight]]></category>

		<guid isPermaLink="false">http://erisds.co.uk/?p=507</guid>
		<description><![CDATA[<img src="http://erisds.co.uk/wp-content/uploads/2009/06/pods-300x162.jpg" alt="Wordpress Pods CMS Plugin" title="Wordpress Pods CMS Plugin" width="300" height="162" class="align-right size-medium" />Have you ever needed to build a website which fit into the "Posts and Page" paradigm of Wordpress 95%, but also needed one or two bits of extra content? I often need to build sites that have a quote/testimonial or banner image tied to individual pages &#038; displayed in the template separately to <kbd>"the_content()"</kbd>. This is fine in Wordpress as long as it remains a one-to-one relationship as it can easily be achieved with <a href="http://codex.wordpress.org/Using_Custom_Fields">custom fields</a> (and check out the <a href="http://wordpress.org/extend/plugins/more-fields/">More Fields</a> plugin for handling this), but achieving a one-to-many or many-to-many relationship in Wordpress requires some more dramatic extension.


Related posts:<ol><li><a href='http://erisds.co.uk/wordpress/spotlight-wordpress-admin-menu-remove-add-new-pages-or-posts-link' rel='bookmark' title='Permanent Link: Spotlight: WordPress Admin Menu &#8211; Remove &#8220;Add New&#8221; pages or posts link'>Spotlight: WordPress Admin Menu &#8211; Remove &#8220;Add New&#8221; pages or posts link</a><small>Back in June I posted about tidying up the WordPress...</small></li>
<li><a href='http://erisds.co.uk/wordpress/migrate-announcement' rel='bookmark' title='Permanent Link: WordPress: Migrate! Easy WordPress Site Migration'>WordPress: Migrate! Easy WordPress Site Migration</a><small>If you work with multiple environments (development, staging, production etc)...</small></li>
<li><a href='http://erisds.co.uk/wordpress/wordpress-2-8' rel='bookmark' title='Permanent Link: WordPress 2.8'>WordPress 2.8</a><small>Over the weekend I updated my blog to Wordpress 2.8....</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p class="small"><strong>Please Note:</strong> This article was written about Pods CMS version 1.6.6 and you&#8217;ll find some of the bugs and issues mentioned are now resolved.</p>
<p><img class="align-right size-medium" title="Wordpress Pods CMS Plugin" src="http://erisds.co.uk/wp-content/uploads/2009/06/pods-300x162.jpg" alt="Wordpress Pods CMS Plugin" width="300" height="162" />Have you ever needed to build a website which fit into the &#8220;Posts &amp; Page&#8221; paradigm of WordPress 95%, but also needed one or two bits of extra content? I often need to build sites that have a quote/testimonial or banner image tied to individual pages &amp; displayed in the template separately to <kbd>"the_content()"</kbd>. This is fine in WordPress as long as it remains a one-to-one relationship as it can easily be achieved with <a href="http://codex.wordpress.org/Using_Custom_Fields">custom fields</a> (and check out the <a href="http://wordpress.org/extend/plugins/more-fields/">More Fields</a> plugin for handling this), but achieving a one-to-many or many-to-many relationship in WordPress requires some more dramatic extension.</p>
<p>To my knowledge there are two plugins for doing this. <a href="http://flutter.freshout.us/">Flutter</a> and <a href="http://pods.uproot.us/">Pods</a>.</p>
<h3>Flutter</h3>
<p>I started out using Flutter as I hadn&#8217;t heard of Pods but found it to be clunky, buggy &amp; unintuitive. When editing a content type (or write panel) created by Flutter it looks as though you are in the Post or Page section depending on where you placed your new content type. This is confusing and unnecessary.</p>
<p>The data types provided with Flutter are quite extensive (it even includes a colour picker). However, Flutter&#8217;s image upload control is buggy and I have experienced Flutter jumping to the wrong page, crashing Firefox and losing data. All-in-all I found it to be hard to use, missing key features and lacking documentation which meant I needed something else.</p>
<h3>Pods</h3>
<p>In essence what Pods does is turn WordPress into Drupal. It allows you to define your own content types with multiple fields for adding data so that you can use WordPress&#8217; admin interface and templating system to manage whatever data you want, be it just additional testimonials, or a full-blown product database. It also allows you to define templates for displaying or listing data types &amp; to write helpers and filters to handle the entry and display of complex data.</p>
<p>Pods&#8217; integration into WordPress is much cleaner, meaning that content editing is much more intuitive than in Flutter. The many options for configuring filters and helpers has lead to a slightly complex admin interface, but one that is still highly usable. Pods also has considerably more documentation than Flutter seems to, although it is still lacking in some areas.</p>
<p>For me, the key bit of functionality which has made me love Pods is the PICK data type. It is essentially a drop-down list control, but instead of requiring you to define the options, it allows you to choose to list out other Pods, or WordPress objects such as Posts, Pages or Users. This means you can build relationships between your content items, and that you create blocks of content for your templates by linking pods to Posts or Pages.</p>
<p>One piece of functionality I needed but isn&#8217;t present is the ability to use a PICK to create a drop-down list of all Posts and Pages to choose one to link to. A PICK data type can currently only list out Pages OR Posts OR Users etc, but not both. It is also not possible to list out Attachments, despite them being stored in the same table as Posts and pages.</p>
<p><a href="http://erisds.co.uk/wp-content/uploads/2009/06/pods-pick.jpg"><img class="align-left" title="Pods PICK interface (modified)" src="http://erisds.co.uk/wp-content/uploads/2009/06/pods-pick.jpg" alt="Pods PICK interface (modified)" width="280" height="311" /></a>As I needed this functionality, I decided to implement it. I have added the ability to PICK from Attachments, Posts &amp; Pages, Posts &amp; Attachments, Pages &amp; Attachments, or Posts, Pages &amp; Attachments. Only two files were modified  (<kbd>manage_pods.php</kbd> to add options to the select, and <kbd>Pods.class.php</kbd> to extend the if/else and SQL statements to choose the right data).</p>
<p>If you would like to use my modified version of the Pods plugin, I have made it available for download. Please first download the <a href="http://wordpress.org/extend/plugins/pods/">full Pods plugin</a> and install it. Then download the <a href="http://erisds.co.uk/wp-content/uploads/2009/06/podsmodified.zip">podsmodified</a> and upload them to the <kbd>wp-content/plugins/pods/core</kbd> folder. I haven&#8217;t done much testing on them but it seems to work OK for me, please let me know if you have any issues &amp; I&#8217;ll endeavour to fix them.</p>
<p>So, with my extension, I have found Pods to be extremely useful in several projects. It is a very powerful and ultimately usable CMS solution. However, there are still a few areas where I feel it could be improved:</p>
<ul>
<li>The power of the PICK data type could be improved as explained above.</li>
<li>I also feel that PICKs could be further improved by allowing users to specify a simple &#8220;enum&#8221;-like data type</li>
<li>The documentation, although extremely useful, could greatly benefit from more detail &amp; in-depth examples</li>
<li>The clunky image upload interface needs work <ins datetime="2010-09-09T12:42:58+00:00"><strong>Update:</strong> This is now improved as of 1.7.6</ins></li>
<li>The interface is usable, but introduces new elements not present in WordPress (namely famfamfam icon buttons) &#8211; by bringing at least the content-editing interface into line with the rest of WordPress I believe this plugin will really come of age <ins datetime="2010-09-09T12:42:58+00:00"><strong>Update:</strong> The work in progress Pods UI plguin alleviates some of these issues, but not the different editor (which is my current biggest niggle)</ins></li>
<li>There is currently no way to link to a Pod from a Post or Page without configuring the relationship from the Pod itself (it would be nice to be able to setup custom fields to select from Pods but not necessary as it can be done the other way around).</li>
<li>There appears to be a bug in the PICK &gt; Categories option</li>
</ul>
<p>In summary, I believe the <a href="http://pods.uproot.us/">Pods plugin</a> to be superior to Flutter and have found it more able to suit my needs. The PICK field type, filters and helpers make for an extremely powerful and expressive CMS and Pods integrates neatly with CMS so as not to confuse editors or clients, which is a key concern. I highly recommend the <a href="http://pods.uproot.us/">Pods plugin</a> and look forward to seeing it mature as it has truly enormous potential.</p>
<p>Download <a href="http://erisds.co.uk/wp-content/uploads/2009/06/podsmodified.zip" onClick="_gaq.push(['_trackPageview', '/downloads/pods-modified166']);">Pods Modified</a>! (For Pods 1.6.6)</p>
<p><strong>Update!</strong> Download the new version of Pods Modified! Same functionality, but for newer versions of Pods <a href='http://erisds.co.uk/wp-content/uploads/2009/06/podsmodified_1.9.1.zip' onClick="_gaq.push(['_trackPageview', '/downloads/pods-modified191']);">podsmodified_1.9.1</a> (For Pods 1.9.1)</p>


<p>Related posts:<ol><li><a href='http://erisds.co.uk/wordpress/spotlight-wordpress-admin-menu-remove-add-new-pages-or-posts-link' rel='bookmark' title='Permanent Link: Spotlight: WordPress Admin Menu &#8211; Remove &#8220;Add New&#8221; pages or posts link'>Spotlight: WordPress Admin Menu &#8211; Remove &#8220;Add New&#8221; pages or posts link</a><small>Back in June I posted about tidying up the WordPress...</small></li>
<li><a href='http://erisds.co.uk/wordpress/migrate-announcement' rel='bookmark' title='Permanent Link: WordPress: Migrate! Easy WordPress Site Migration'>WordPress: Migrate! Easy WordPress Site Migration</a><small>If you work with multiple environments (development, staging, production etc)...</small></li>
<li><a href='http://erisds.co.uk/wordpress/wordpress-2-8' rel='bookmark' title='Permanent Link: WordPress 2.8'>WordPress 2.8</a><small>Over the weekend I updated my blog to Wordpress 2.8....</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://erisds.co.uk/wordpress/spotlight-wordpress-pods-plugin/feed</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
	</channel>
</rss>

