Looks like its just your PHP formatting, you have the right idea! try this:
<pre class="prettyprint"><code class="language-php">
<?php
if (is_page( 'Home' ) {
$class="active";
}
elseif (is_page( 'About' ) {
$class="active";
}
else {
$class="";
}
?>
<li class="<?php echo $class; ?>"Home</li>
<li class="<?php echo $class; ?>"About</li>
</code></pre>
Related Posts:
- wp_nav_menu(), how to change class?
- Add custom classes to anchor in wp_nav_menu
- Strict Standards Error bootstrap navwalker
- How to add menu support to a theme?
- How to add a section to the menus configuration, offering hard coded items?
- Extend walker – navigation, adding data attribute to a tag
- Displaying wp menus by name without using theme locations
- how to change WordPress menu markup/classes
- Setting a Default ‘Theme Location’ When Creating a Menu
- How to add categories to wp_list_pages()
- .sub-menu or .children?
- Arguments ignored/markup changed in wp_nav_menu if no menu is selected
- My Admin bar covers my sticky navbar [closed]
- WordPress is adding margins and padding to my custom menu?
- Primary navigation menu & footer not showing in category / tag page
- Using a page as home, how do I prevent nav from setting both home and page links active?
- Custom markup with wp_nav_menu based on pages
- Get the amount of posts on a given page
- how do i develop a global nav and local nav to be wordpress dynamic?
- Theme development: menu links a tabbed page with page jumps
- how to hide home nav link in wordpress
- How do I implement jPanelMenu?
- Custom nav menu not showing
- How do I display a greyed out next_post_link when there is no next post
- Programatically Created Menu not Editable in Dashboard
- Does single webpage do not need navigation to create a slug in permalink?
- White screen of death on index.php page 3 and above?
- 3 Level Menu Navigation (3rd Level not displaying)
- How can I show a custom WordPress menu anywhere I want on my website?
- Show all menu levels except top level. How to exclude top level of a menu?
- WordPress Menu item > Sub menu Class update
- Move the social media icons to the left of a WordPress nav menu for Soledad child Theme
- Need help with adding custom wordpress menu and sub-menu
- How to achieve this navigation style in wordpress navigation
- Fallback dosen’t work when not using ‘menu’ attribute
- How to add drop symbol to parent nav items which have child
- WordPress 3.9 two menus in same position?
- Strict Standards Error bootstrap navwalker
- How to make navigation a list without a plugin? [duplicate]
- can’t add EVENT LISTENER to a element
- Fatal error: Call to undefined function the_posts_navigation()
- Bootstrap 4 mobile menu not working for WordPress Development
- wp_nav_menu_items callback not triggered
- Disable interactivity for core navigation
- Menu items description? Custom Walker for wp_nav_menu()
- How to define and link full path to css located at a random folder on header.php
- Sizing screenshot.png without losing aspect ratio
- Software for WordPress Theme and Plugin Development? [closed]
- When to use is_home() vs is_front_page()?
- What is the preferred way to add custom javascript files to the site?
- Get the blog page URL set in Options
- How to create .pot files with POedit?
- How do I get the theme URL in PHP?
- Why when I submit a form in wordpress it loads a 404 page though URL is correct
- What is the constant WP_USE_THEMES for?
- Worthwhile to restrict direct access of theme files?
- How Do I Protect My Premium WordPress App Theme from Copying?
- How to detect mobile devices and present them a specific theme?
- Using wp_add_inline_style without a stylesheet
- How to add posts to custom menus?
- WordPress Theme Preview Image
- How To extend WP_Customize_Control
- What is the difference between front-page.php and home.php? [duplicate]
- How can I get page slug
- Does the functions.php file ever get called during an AJAX call? Debug AJAX
- When to use _e and __ for the translation?
- What is a Theme textdomain?
- How to show a custom meta box on the “Quick Edit” screen?
- How to add CSS class to custom logo?
- How to add custom css file in theme?
- How important is it to enqueue a theme’s stylesheet?
- CSS not updating in browser when I change it
- Display Search Result Count
- theme path in javascript file
- Is wp_is_mobile() effective?
- Display Menu Name using wp_nav_menu
- Making update notification functionality for my themes
- What questions do you ask when asked to give an estimate on theme development?
- How to remove dashicons.min.css from frontend?
- How do I remove a pre-existing customizer setting?
- Minimum Template Files for Theme Development
- What’s the difference between home.php and index.php?
- pass object/JSON to wp_localize_script
- get_template_part vs action hooks in themes
- Theme Activate Hook
- Solutions for generating dynamic javascript / CSS
- wp_redirect() – headers already sent
- Can I create my own “Recent Posts” widget or customize the existing one?
- Custom single template for a specific category
- how can I add an icon/image for a child theme?
- How can I add a URL field to the attachments window?
- The the_post_thumbnail without srcset?
- The proper way to include/require PHP files in WordPress
- Get the first image from post content (eg.: hotlinked images)
- after_setup_theme always runs
- When to use add_action(‘init’) vs add_action(‘wp_enqueue_scripts’)
- Getting failure when using filemtime() with wp_enqueue_style
- Do I actually need to link my theme’s style.css in the theme files
- Why is wp_head() creating a top margin at the top of my theme header?
- How to store widget fields data as an array?