Idea #1 is correct if your template use body_class()
like
<body <?php body_class(); ?>>
In this case the body tag will be something like:
<body class="page page-id-6 page-template-default">
If the id of viewed page is 6 and template used is the default.
See Codex
However, in pages the global $post
variable is available even in the header and before calling the_post()
. So $post->post_name
will contain the slug of your page and you can make use of it as you want.
Related Posts:
- How to get IDs for objects in menu branch?
- Show only 2nd level of navigation depending on active navigation
- Remove navigation from header in custom page template
- How to retrieve depth of menu into template
- Output menu navigation in php file
- How to make the Primary Menu stay the same in the PC and mobile versions of the Twenty Sixteen theme
- Change submenu markup
- How to modify wp-includes without messing my wordpress installation?
- WordPress template – How to add class to li tag if submenu exist
- How can I switch pages?
- Add a submenu to wp_nav_menu
- Automatically going to the first page in a hierarchy?
- How to add search to menu?
- Is it all right to put the whole tag into template_part file?
- Create link/button to create new post using specific template
- wp_nav_menu doesn’t show on index page
- Setting up menus before making a template live
- Display a portion/ branch of the menu tree using wp_nav_menu()
- Display only page specific sub menu items using Custom Walker
- non-clickable placeholder in the menu
- Ways to give a wp_list_pages menu link specific class names?
- I want remove last after wp_nav_menu
- Add log in link to menu in Twenty Twelve
- Organizing by super-categories (or nested categories)?
- Adding first and last class to Menu on top level only
- wp_list_pages – show pages immediately 1 level below current level
- Add within the output of
- How do I get my wp_nav_menu single category page to highlight the parent?
- Where to update the Static Pages Blacklist for Multisite Install?
- Vertical Sidebar Menu Parent and Child not displaying correctly [closed]
- Hide Menu items base on capability
- How to show Home Page link in WordPress Menu and how to add an icon to this?
- How to add custom menu item on plugin activation?
- Outside the loop, how can I echo the current page’s menu title?
- Use menu class in walker function
- Menu link to all posts (all categories included)
- How do you return a menu with the menu name?
- do_action appearing outside of menu?
- You do not have permission to create Navigation Menus – Twenty Twenty-Two theme
- Walker class conditional based on parent menu item label or custom css class
- Creating a navigation menu to see where you are on your website
- Custom format nav menu only using div and a
- ‘wp_get_nav_menu_items’, when fired inside of the ‘wp_update_nav_menu’ hook, returns old menu items, instead of new
- Sticky Header in WordPress using BootstrapWP theme [closed]
- Walker Class – Check if menu item has description and if so add class to li
- Multiple languages menus problem
- Switch from hover to click on Twenty Twelve Menu
- How to override menu markup?
- How to remove dropdown from wp_nav_menu
- Is it possible to add a dynamic link in the main navigation in a child theme
- How to change menu structure?
- Insert a div class inside wordpress menu
- Retrieve Menu name for nav_menu_item
- Edit the (automatic) HTML layout of nav menus
- How to make wordpress nav menu use post custom meta data
- Is it possible to make the heading on a page different text to the text of the menu item?
- How to Structure Pages and Subpages
- Add custom path to url to specific pages
- CTA button that is only visible to some of my users
- How do add a menu with levels within page [closed]
- Hide menu item when users are logged in/out
- add another html tag after li element in wp_nav_menu
- How do I change/remove styling (top border) on main menu for active page and hovering (Avada Theme)
- How to add scroll IDs to WordPress menu anchors
- WP nav menu + Bootstrap, add role=”menu” to UL
- Display pictures instead of text in menus
- how to check if given page is active page
- how to set the link in wordpress such that on clicking it doesn’t open another page but go to the bottom of same page
- custom walker class for own menu?
- WordPress Menu – creating a fake link [closed]
- Add a menu metabox to post edit page
- Setting or plugin for showing submenus horizontally under the main menu, and keep them after selection
- New wp menu menu styling
- (Mobile) Hamburger menu disappeared from a page (only one)
- Add div content to my already existing menu
- Hiding menu on specific pages
- Bootstrap Menu bar shows up a toggle in Desktop Mode
- For a menu custom link (without a link) a “#” is appended. Can this just be blank, i.e. NO link?
- sidebar navigation problem with child pages not all display.?
- How to point menu to my homepage
- save_post() on Menu Save
- dot.com/car1 does work, but dot.com/transport/car1 doesn’t work
- code to add an extra selection to the menu editor
- update_post_meta breaking wp_update_nav_menu_item
- Building a menu from a large number of pages?
- Accidental reverse order of menu items in one menu
- How to call a certain object/menubar in a PHP file
- How do I remove a menu from a theme?
- Access CSS Classes specified in Menu options
- How to output the menue structured for tabbed navigation?
- Walker for menus
- Custom Menu based off custom header
- Remove “Next Post” in nav_menu
- Adding an additional menu in WordPress
- Making current_page_item work with wp_list_pages in sidebar on post pages
- Menu not Showing on Mobile or While the page is shrinked
- My Menu Disappears on my Custom Link Homepage on Mobile
- How to centre menu items on horizontal nav bar? (e.g. make margins equal) [closed]
- Add A Menu Item To A WP_Nav_Menu Navigation via PHP Function
- Database structure Menu Item