Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1330727

    Hello dear Kriesi team,
    I would like to create two different start pages. Once a start page for mobile devices and a start page for PC and large screens. Is that possible with Enfold?
    With best regards
    Severin

    #1330752

    Hey Severin,
    There is not a built-in feature for this but you could try this function. Try adding this code to the end of your functions.php file in Appearance ▸ Editor:

    
    function custom_mobile_homepage() {
        ?>
    	<script>
    	if (window.location.pathname == '/' && jQuery(window).width() <= 480) {
    	   window.location = "/mobile-homepage/";
    	}
    	</script>
        <?php
    }
    add_action( 'wp_head', 'custom_mobile_homepage', 10 );
    

    adjust the /mobile-homepage/ to your new page.

    Best regards,
    Mike

    #1330894

    Hello Mike,
    Unfortunately it does not work.
    Take a look yourself.
    But then please set it to inactive again.
    Thank you very much for your help.
    Best regards, Severin

    #1330971

    Hi,

    Thank you for the info.

    You might be able to use the wp_is_mobile function to detect if the current device used is mobile and the wp_redirect function to redirect the users to a different page if the first condition is true.

    // https://developer.wordpress.org/reference/functions/wp_is_mobile/
    // https://developer.wordpress.org/reference/functions/wp_redirect/

    Best regards,
    Ismael

    #1331027

    can you try mikes post with that if clause

    function landingpage_for_mobile() {
    if(wp_is_mobile()){
    ?>    
    <script>
      if (window.location.pathname == '/' ) {
         window.location = "/mobile-home/";
      }
    </script>
    <?php
    }
    }
    add_action( 'wp_head', 'landingpage_for_mobile', 10 );

    or:

    function redirect_mobile_devices() {
        if ( wp_is_mobile() && is_front_page() ) {
            wp_safe_redirect( get_site_url(). '/mobile-home', 301 );
            exit;
        }
    }
    add_action( 'wp', 'redirect_mobile_devices' );
    #1331075

    Hi,
    Thanks for the login, the reason this didn’t work was because you are forcing jQuery to load in the footer so you were getting an error, to correct I removed the jQuery part of the script and now it works. Although it is disabled as you requested.
    This is the new script.

    function custom_mobile_homepage() {
        ?>
    	<script>
    		const mediaQuery = window.matchMedia('(max-width: 480px)');
    	if (window.location.pathname == '/' && mediaQuery) {
    	   window.location = "/startseite-mobil/";
    	}
    	</script>
        <?php
    }
    add_action( 'wp_head', 'custom_mobile_homepage', 10 );

    Best regards,
    Mike

    #1333499

    Hi Mike,
    thank you, but unfortunately it doesn’t work completely yet. The diversion works. But when I activate the function, it is also active for the computer view. Best regards, Severin

    #1333515

    Hi,

    Did you try @Guenni007’s suggestion above? The code should redirect the user to the specified page (mobile-home) on mobile devices.

    function redirect_mobile_devices() {
        if ( wp_is_mobile() && is_front_page() ) {
            wp_safe_redirect( get_site_url(). '/mobile-home', 301 );
            exit;
        }
    }
    add_action( 'wp', 'redirect_mobile_devices' );
    

    Best regards,
    Ismael

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.