• Resolved woody18

    (@woody18)


    Hi
    i’m wondering if I can do something like this in the condition:

    is_page ('*Helsinki*)

    in order to show a menu item for all pages containing “Helsinki” in the slug

    thanks for Your Ideas

    Urs

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author shazdeh

    (@shazdeh)

    Hi,

    You could do:

    
    is_page() && strpos( $GLOBALS['post']->post_name, 'Helsinki' ) !== false
    

    The strpos checks if the substring (Helsinki) exists anywhere within the original string (here: the post slug). Of course, you could use preg_match and do super complex pattern detection with Regex as well.

    Thread Starter woody18

    (@woody18)

    You are me HERO! Thanks a lot.

    Knowing that I have only pages (no posts/articles) I omitted “is_page()”.
    Hope that is no problem – seems that works.

    Plugin Author shazdeh

    (@shazdeh)

    Glad to be of help.
    It might be a good idea to put that in; in archive pages the $post variable refers to the first post in the list, so there’s a chance you might end up showing the menu in unwanted places. Also it may be $post is not set at all (say maybe in custom pages added by plugins, etc.) and $GLOBALS['post']->post_name would generate an error, whereas the is_page() check would prevent that. To ensure there’s no error you could add a isset( $GLOBALS['post'] ) instead.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘conditional menu item with wildcard’ is closed to new replies.