• The output of the site navigation for Mega Menu doesn’t output the “url” & “name” tags needed for schema in https://schema.org/SiteNavigationElement.

    I have edited the code in /megamenu/classes/walker.class.php on lines 130 & 138

    original

    $item_output .= '<a'. $attributes .'>';
    $item_output .= '</a>';

    edited

    $item_output .= '<a itemprop="url"'. $attributes .'><span itemprop="name">';
    $item_output .= '</span></a>';

    I don’t want to lose my changes when this plugin updates, what kind of function can I use in my child theme to overwrite the plugin code here?

Viewing 1 replies (of 1 total)
  • Plugin Author megamenu

    (@megamenu)

    Hi sitedesigndev,

    If you look at line 143 you will see the whole <li> is run through a filter.
    You will need to use this filter to modify the returned value. Untested, but something like:

    function add_item_props( $item_output, $item, $depth, $args ) {
    
        $return_value = $item_output;
        // at this point $return value will be something like
        // <li class='mega-menu-item'><a href='url'>Link name</a></li>
    
        // modify the return value using regex or str_replace
        // you are on your own for this bit
    
        return $return_value;
    }
    add_filter('megamenu_walker_nav_menu_start_el', 'add_item_props', 10, 4);

    Regards,
    Tom

Viewing 1 replies (of 1 total)
  • The topic ‘Schema for SiteNavigationElement’ is closed to new replies.