Wordpress dynamic navigation function for highlighting single post tabs
- by user269959
I am trying to write a function that i can reuse in my wordpress themes that will allow me to build robust dynamic navigation menus. Here is what i have so far:
function tab_maker($page_name, $href, $tabname) {
//opens <li> tag to allow active class to be inserted if tab is on proper page
echo "<li";
//checks that we are on current page and highlights tab as active if so
if(is_page($page_name)){
echo " class='current_page_item'>";
}
//closes <li> tab if not active
else {
echo ">";
}
//inserts the link as $href and the name of the tab to appear as $tabname then closes <li>
echo "<a href=$href>$tabname</a>";
echo "</li>";
}
This code works as expected except i cant enable it to highlight for a single blog post as the page names are dynamic. I know about the wordpress function is_single() which ive used to implement this feature in previous nav menus but i cant find a way to integrate it into this function. appreciate any help!