Thursday, September 15, 2022
HomeWordPress DevelopmentDeclaration of mandoe_menu_walker::start_el(&$output, $merchandise, $depth, $args) have to be appropriate with Walker::start_el(...)

Declaration of mandoe_menu_walker::start_el(&$output, $merchandise, $depth, $args) have to be appropriate with Walker::start_el(…)


I’ve initially hard-coded menu hyperlinks into the mega menu of mandoemedia.com so as to obtain the icon and outline of every hyperlink.

enter image description here

I am questioning whether it is doable to transform these submenus into menus I can add via Look > Menus whereas nonetheless sustaining the icons and descriptions.

I see via Display Choices I can add a Description to every menu merchandise and a CSS Class which I can use as in picture filename.

From this web page, I’ve created a customized plugin:

<?php
/*
Plugin Title: Mandoe Mega Menu Helper
Description: Permits pictures and descriptions in mega menus
Writer: Steve Doig
Model: 1.0.0
*/

class mandoe_menu_walker extends Walker {
    operate start_el(&$output, $merchandise, $depth = 0, $args) {
        world $wp_query;
        $indent = ( $depth ) ? str_repeat( "t", $depth ) : '';

        $class_names = $worth="";

        $courses = empty( $item->courses ) ? array() : (array) $item->courses;

        $class_names = be a part of( ' ', apply_filters( 'nav_menu_css_class', array_filter( $courses ), $merchandise ) );
        $class_names=" class="". esc_attr( $class_names ) . '"';

        $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $worth .'>';

        $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
        $attributes .= ! empty( $item->goal )     ? ' goal="' . esc_attr( $item->goal     ) .'"' : '';
        $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
        $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';

        $prepend = '<robust>';
        $append = '</robust>';
        $description  = ! empty( $item->description ) ? '<span class="mm-mm-subtext">'.esc_attr( $item->description ).'</span>' : '';

        if($depth != 0) {
            $description = $append = $prepend = "";
        }

        $item_output = $args->earlier than;
        $item_output .= '<a'. $attributes .'><img src="' . get_stylesheet_directory_uri() . '/img/icon-' . $class_names .'" alt="' . $item->title . '" class="mm-mm-icon">';
        $item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
        $item_output .= $description.$args->link_after;
        $item_output .= '</a>';
        $item_output .= $args->after;

        $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $merchandise, $depth, $args );
    }
}

?>

however when activating this plugin I obtain an error:

Deadly error: Declaration of mandoe_menu_walker::start_el(&$output,
$merchandise, $depth, $args) have to be appropriate with
Walker::start_el(&$output, $data_object, $depth = 0, $args = [],
$current_object_id = 0) in /wp-content/plugins/mm-mega-menu-helper/mm-mega-menu-helper.php
on line 10

Assist appreciated.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments