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 630 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

How to Remove Name and Website Fields in Bricks Comment Forms

How to Remove Name and Website Fields in Bricks Comment Forms

Updated on 14 Mar 2024 In the BricksLabs Facebook group a user asked: What is the best method to remove fields from the Bricks "Comments"…
Pro
Setting a Bricks template for Parent pages

Setting a Bricks template for Parent pages

This Pro tutorial shows how bricks/active_templates filter can be used to programmatically assign a Bricks template to all singular pages (of any post type) that…
Show Product Categories Count Using Bricks Filter Hook

Show Product Categories Count Using Bricks Filter Hook

Unable to find terms count from the Dynamic Data provided by Bricks theme? It's okay, this simple tutorial shows you how to properly get the…
Categories:
Tags: