I'm trying to add a display:none to a walker menu in functions but it's not working.
Basically if post status is "draft" then...
Any ideas where I've gone wrong?
if ( isset( $item->classes[0] ) && ! empty( $item->classes[0] ) ) {
$custom_class_data = ' data-classes="' . $item->classes[0] . '"';
}
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . $class_columns . '"' : '';
$style = $style ? ' style="' . esc_attr( $style ) . '"' : '';
$id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item->ID, $item, $args );
$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
global $post;
$page_id = $post->ID;; // example id of your page
$page = get_page( $page_id );
if( $page->post_status == 'draft' ) :
$output .= '<li role="menuitem" style="display: none"' . $id . ' ' . $class_names . ' ' . $column_width . $custom_class_data . $style . ' >';
else:
$output .= '<li role="menuitem" ' . $id . ' ' . $class_names . ' ' . $column_width . $custom_class_data . $style . ' >';
endif;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
} // End if().
You already have
$style
variable that stores styles, I would do something like that: