This topic has 5 replies, 2 voices, and was last updated 8 years by sharmstr.

  • Author
  • #108255
     bizeulabs
    Participant

    Hi.

    I want to know how I can hide the sidebar on mobile and tablet. I have tried used wp_is_mobile() but I think I’m not doing well because I have not gotten.

    can anybody help me?

    Thank you.

    #108260
     sharmstr
    Moderator

    That was discussed here: https://archived.seventhqueen.com/forums/topic/mobile-sidebars-and-menu#post-73978

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #108267
     bizeulabs
    Participant

    Thank you sharmstr

    I know how to hide the sidebar with CSS but I wanted to know how to make non load the sidebar by PHP, on pages and posts.

    I tried with this code in right_sidebar.php:

    <?php
    //create right sidebar template
    if ( !wp_is_mobile() ) {
    kleo_switch_layout(‘no’);
    }else{
    kleo_switch_layout(‘rigth’);
    }
    ?>

    But it doesn´t work. And I don´t know why.

    #108274
     sharmstr
    Moderator

    A few issues –

    1 – Your logic is wrong/backwards. Your code is saying “if its not mobile, show full width. if it is mobile, show the sidebar”.

    2 – You’ve misspelled right.

    3 – According to WP you shouldn’t be using it in themes: https://codex.wordpress.org/Function_Reference/wp_is_mobile

    But to answer your question, by the time it gets to right-sidebar.php its too late. You could have tested that by merely changing ‘right’ to ‘no.

    If you look in the kleo_prepare_layout function, you’ll see that you can filter it. So its as simple as putting this in your child theme.

    COPY CODE
    
    add_filter( 'kleo_page_layout' , 'remove_sidebar_mobile' );
    function remove_sidebar_mobile() {
    
        if ( wp_is_mobile() ) {
            $layout = 'no';
        }else{
           $layout = 'right';
        }
        return $layout;
    }
    
    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #108297
     bizeulabs
    Participant

    It works perfectly.

    Thanks for the explanations and resolve the doubts.

    #108300
     sharmstr
    Moderator

    You’re welcome.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

Viewing 6 posts - 1 through 6 (of 6 total)

The forum ‘General questions’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?