Jump to content

WordPress dynamic menu with custom post types


slobjones

Recommended Posts

This topic combines WordPress conditional statements with PHP. Hoping to get some help here.

 

I'd like to create a dynamic WordPress menu with a mix of static pages and custom post type archives that applies a class of "current" to the current tab. The example below uses 1) Static page set as Home 2) Static page 3) Custom post type archive 4) Static page for blog content.

 

Tried to edit the code from my previous menu, but it's not working (see below). I'd appreciate any assistance!

 

Thanks.

 

<ul>
<li<?php if ( is_front_page() ) { echo ' class="current"'; } ?>><a href="/">Home</a></li>
<li<?php if ( is_page('my-page') { echo ' class="current"'; } ?>><a href="/my-page/">My  Page</a></li>
<li<?php if ( is_post_type_archive('my-custom') && is_single()) { echo ' class="current"'; } ?>><a href="/my-custom/">My Custom Posts</a></li>
<li<?php if ( is_page('blog') { echo ' class="current"'; } ?>><a href="/blog/">Blog</a>    </li>
</ul>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.