Blog Pile, Wordpress

WordPress Shazam! Your Category is Now a Page

cc licensed flickr photo shared by ElDave

The main navigation of most WordPress sites is driven by cycling through all of the content that are WordPress pages– which is nice, but sometimes you have content that you don;t want cluttering the navbar. Or maybe you want to insert something that is not a Page into the navbar. I’ve been amazed that so few people seem to know how to subvert it, and below is a little trick I use when I want to wedge some other kind of WordPress content into the navbar by Pages process.

Mostly this is in your HEAD… I mean the header.php file of your templates that generates it as an Unordered List:

The first li item creates the Home link, and in thes case applies some CSS logic if the home page is in view. The rest of it happens in the PHP code statement that uses the WordPress fucntion to return a list of all Pages and putting each one in an <li> tag and set to link from the title.

To customize which Pages are used, you need to find the WordPress ID of the pages you want to include or exclude; the easy way is to go to the Edit Pages part of your dashboard, mouse over the page links, and look for the part of the URL that says id=X

If you don’t want all your pages, you can either exclude certain ones, say ID 5 and 11 by changing the line above to:

Or, if in a current case, I have tons of pages but only want say 5 of them in my navigation, I can use:

If you want to have more control over the order of links than alphabetical, add this little bit of code (broken in half for readability):

and for each page, you can modify the value of the Order field for your Page (under attributes) using integers to define the load order.. I love how it says below this box:

Pages are usually ordered alphabetically, but you can put a number above to change the order pages appear in. (We know this is a little janky, it’ll be better in future releases.)

It has been just as janky for like 5 years 😉

What if you want one of your nav links to connect to something outside your blog? If you can live with it before or after the list of pages, you can just card code an extra <li> item

See, not too hard to customize.

And now the magic tricks– I had a case today 9and elsewhere) where I wanted something like a WordPress Category or Tag Name to be part of my navbar flow, and needing it to be somewhere in the middle of my page orders (thus I could not use the extra <li> insertion).

I do this by a little misdirection. Let’s say I use a tag for my resource site called “Tips” to organize all my posts that are helpful tips- I thus have some sort of URL like that I want to be part if my nav set of links.

First I create a fake placeholder WordPress page called My Cool Tips, which you can get to via the URL

I then go into by Apache server settings for this domain, and add a permanent redirection like:

What this does is to tell my webs serve to take any request coming towards my site at is immediately re-routed to

but because WordPress thinks that this URL is a page, it sits it in my navbar like a Page, but any links to it are sent to the tag page archive.

Now, often, like on a hosted web server, you do not have access to the server apache configuration files. No problem! You can just slap it at the top of the .htaccess document inside your WordPress home directory.

I’ve done that here on CogDgBlog- I have a static page that sites outside of WordPress (it uses the WP include to access the nav bar, but it is not managed by WordPress; it is a stand alone PHP doc:

But that URL is a bit…. “janky”, so in my .htaccess file, I added at the top:

RedirectPermanent /best

which sends any request to to the actual URL.

WordPress is great, but it is greater when you start tweaking and janking its insides out!

If this kind of stuff has value, please support me by tossing a one time PayPal kibble or monthly on Patreon
Become a patron at Patreon!
Profile Picture for CogDog The Blog
An early 90s builder of web stuff and blogging Alan Levine barks at on web storytelling (#ds106 #4life), photography, bending WordPress, and serendipity in the infinite internet river. He thinks it's weird to write about himself in the third person. And he is 100% into the Fediverse (or tells himself so) Tooting as

Leave a Reply

Your email address will not be published. Required fields are marked *