• Resolved craigstanfield

    (@craigstanfield)


    Hi All,

    I’m working on migrating an existing site to AMP. Firstly I’ve done a fair few of these and I’m loving how this plugin has progressed.

    However on my latest site I have an issue with the menu when viewed on the desktop using the ?amp query in transitional mode.

    The existing code uses foundation and it uses brettsmason Walker_Nav_Menu to create the unordered list used for the menu.

    I use is_amp_request and isset($_GET[amp_get_slug()) to determine if the page is amp and if it is I manually add the accordian menu class. This works great on mobile versions of the page and the default non amp behaviour remains the same. When I view an AMP page on desktop however the class is still added (as obviously the page is amp and still has the ?amp query).

    SO how can I now add an additional test in my if statement that can determine if the page is being viewed in dewsktop mode (width is over 768px) I would normally use some javascript to say put the width into a cookie but with the restictions on AMP this is not an option so ultimately what my question biols down to is does this amp plugin have a helper function or amp compaitible script that can feed the width into something i can test to determine if i manually add the accordian-menu class.

    This is what i have in function that calls the Walker:

    function joints_top_nav() {
        $menuClass = 'medium-horizontal menu';
        if (
            function_exists('amp_is_request') &&
            amp_is_request() &&
            isset( $_GET[ amp_get_slug() ] )
        ) {
            $menuClass .= ' accordion-menu';
        }
    	return wp_nav_menu(array(
    	    'echo'              => false,
    		'container'			=> false,						// Remove nav container
    		'menu_id'			=> 'main-nav',					// Adding custom nav id
    		'menu_class'		=> $menuClass,	// Adding custom nav class
    		'items_wrap'		=> '<ul id="%1$s" class="%2$s" data-responsive-menu="accordion medium-dropdown">%3$s</ul>',
    		'theme_location'	=> 'main-nav',					// Where it's located in the theme
    		'depth'				=> 5,							// Limit the depth of the nav
    		'fallback_cb'		=> false,						// Fallback function (see below)
    		'walker'			=> new Topbar_Menu_Walker()
    	));
    }

    In my functions I have added a generic theme support function:

    add_theme_support(
        'amp',
        array(
            'nav_menu_toggle' => array(
                'nav_container_id' => 'top-bar-menu', // The menu
                'nav_container_toggle_class' => 'show-menu',
                'menu_button_id' => 'responsive-menu-toggle', // The button
                'menu_button_toggle_class' => 'is-active',
            ),
            'paired' => true,
        )
    );

    If no such function exists with AMP is it something that would be considered for the future? And also what would you guys suggest for this kind of scenario? I realise I could double the code and have a desktop and a mobile menu but I’d sooner keep the original code as it is as much as I can in line with it’s original responsive functionality.

    I also have the issue reported on here with submenu’s not working. In my case the items are not shown but I can live with that to a poont.

    thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support Milind More

    (@milindmore22)

    Hello @craigstanfield

    Thanks for the support topic, can you please share your site’s URL and site health information using this form.

    Also, please share some screenshots using services like lightshot so we can understand your requirement better.

    Thread Starter craigstanfield

    (@craigstanfield)

    Hi Milind,

    The non amp live site can be seen @ https://www.leanuk.org/ I’m trrying to mimic the same behaviour in AMP. In previous posts with earleier versions of this excellent plugin the suggestion has been to consider using things like amp-sidebar or amp-mega-menu but as this is an existing working menu I don’t really know how to get the exact same functinality independent of viewing so I have sub menu’s which expand and contract when clicked/touched.

    As explained i have the menu to work by adding a class to the top level ul but I do not know of a way how the class can be removed if the viewport is not a mobile device. Mainly my concern on this is with a view to eventially serving all pages in AMP for all devices!

    thanks

    Plugin Support Milind More

    (@milindmore22)

    hello @craigstanfield

    I will recommend using additional check with wp_is_mobile function

    Thread Starter craigstanfield

    (@craigstanfield)

    Hi @milindmore22 ,

    Thanks for the reply and to confirm that has fixed my issue, sometimes one can’t see the wood for the trees. Just need to work out how to get the submenu side of it to work and this one is ready to go.

    thanks again

    Plugin Support Milind More

    (@milindmore22)

    Hello @craigstanfield

    I will recommend keeping the submenu expended for AMP pages.
    you can add amp specific styles with html[amp]

    eg:
    the style from your current site can be modified as

    
    @media screen and (max-width: 39.99875em)
    html[amp] .top-bar ul {
        background-color: #fff;
        display: block !important;
    }
    
    Thread Starter craigstanfield

    (@craigstanfield)

    Hi Milind,

    Ok thats good but my client is expecting the same behaviour :-s. I’ve been extending the walker nav function and it is coming on well Thanks again for the support

    Plugin Support Milind More

    (@milindmore22)

    Hello @craigstanfield

    You can check other themes like Astra or Neve for reference or you can check this code which I added for the Chaplin theme.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘AMP responsive menu desktop’ is closed to new replies.