• Resolved Anne

    (@anne-wsib)


    I have put in the following code and get an error
    Parse error: syntax error, unexpected $end in xxxxxxx/wp-content/themes/simone-child/functions.php on line 22.

    <?php /*
    
      This file is part of a child theme called simone-child.
      Functions in this file will be loaded before the parent theme's functions.
      For more information, please read https://codex.ww.wp.xz.cn/Child_Themes.
    
      Add your own functions below this line.
      ========================================== */ 
    
    // theme's functions.php or plugin file
    add_filter( 'if_menu_conditions', 'my_new_menu_conditions' );
    
    function my_new_menu_conditions( $conditions ) {
    $conditions[] = array(
    	'name'		=>	'Schedule 2', //name of condition
    	'condition'	=>	'is_custom_category' //condition
    ;
    
    function is_custom_category() {
    	return is_category('sched2');
    }
    }

    https://ww.wp.xz.cn/plugins/if-menu/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Anne

    (@anne-wsib)

    I could not get this working but found this instead which works perfectly
    menu-items-visibility-control
    I just put the condition of schedule 1 or 2 so I can have the same site for different scheduled information AND it works with the language translate. Hope this helps someone

    lbsteele

    (@lbsteele)

    The closing parenthesis for the array is missing (it should be just before the semi-colon)

    You could also do it this way which is much simpler:

    add_filter( 'if_menu_conditions', 'my_new_menu_conditions' );
    
    function my_new_menu_conditions( $conditions ) {
      $conditions[] = array(
        'name'    =>  'Schedule 2', // name of the condition
        'condition' =>  function($item) {          // callback - must return TRUE or FALSE
          return is_category( 'sched2' );
        }
      );
    
      return $conditions;
    }
    Plugin Author Andrei

    (@andreiigna)

    Thank you for trying this plugin.

    The code from CHomko should work, thanks

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘conditional statement for a category’ is closed to new replies.