• littleL

    (@littlel)


    Hi

    I need some help please, I’m not very familiar with php.

    How would you check something like the following code dynamically?

    if ( is_page('home') ) { do something }
    elseif ( is_page('about') ) { do something }
    ...

    I’m trying to add css class to the actual links for the nav menu, I found this code which works lovely

    function add_nav_class($output) {
    $output= preg_replace('/<a/', '<a class="your-class"', $output, -1);
    return $output;
    }
    add_filter('wp_nav_menu', 'add_nav_class');

    but I need to do something like this, which has a different class if you are on that page.

    function add_nav_class($output) {
    if (is_page(WHAT_GOES_HERE?)) { $menuclass = '<a class="menuOn"'; }
    else { $menuclass = '<a class="menuOff"'; }
    
    $output= preg_replace('/<a/', $menuclass, $output, -1);
    return $output;
    }
    add_filter('wp_nav_menu', 'add_nav_class');

    hope that makes sense..
    many thanks!

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Need help with checking current page’ is closed to new replies.