4th Jul '25
/
0 comments

Making a Nav Menu Item Active for Custom Post Type Single Views in WordPress

Consider this scenario:

CPT: project

Page titled "Project" is being used to show a list/grid of all the projects rather than the CPT archive.

When viewing a single project, you want this Project Page's nav menu item to become active.

This Pro tutorial provides the code for using nav_menu_css_class WordPress filter to make the "Project" menu item active when viewing a single post of project custom post type.

Note that this can also be done using custom CSS but PHP solution is more solid.

Add the following in child theme's functions.php (w/o the opening PHP tag) or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 633 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Filtering out Media Items from “Select post/page” Bricks control

Filtering out Media Items from “Select post/page” Bricks control

The dropdown that appears after choosing "Internal post/page" when setting a link in Bricks shows media (attachment) items besides Pages, Posts and other CPTs. If…
Pro
x Number of Random Bricks Query Loop Items(s) to be Shown Every x Hours

x Number of Random Bricks Query Loop Items(s) to be Shown Every x Hours

Showing how to display one random row of a Meta Box group for an hour and then output another random row.
Pro
How to programmatically add a class to an element in Bricks

How to programmatically add a class to an element in Bricks

This Pro tutorial shows how a dynamic class can be added to a query loop element in Bricks programmatically. Let's take an example where posts…