Languages in Meta Slider

  • Author
    Posts
  • #2616

    Andrew Misplon
    Keymaster

    Hi Jordi

    Great to hear from you; thanks for your support.

    I think the easiest would be to copy header.php (not cut) from the parent theme folder and paste it into your child theme folder. Then, replace line 66:

    <?php ultra_render_slider(); ?>
    

    with the following:

    <?php
    
    $currentlang = get_bloginfo( 'language' );
    
        if ( is_front_page() ) {
    
             if ( $currentlang=="es-ES" ) {
                     echo do_shortcode( '[metaslider id=32]' ); // Spanish
             }
    
             if ( $currentlang=="ca-CA" ) {
                     echo do_shortcode( '[metaslider id=33]' ); // Catalan
             }
    
        }
    
        else {
        	ultra_render_slider();
        }
        
    ?>

    The only additional step required would be to replace the Meta Slider ID’s of 32 and 33 that I’ve used above, with your own.

    Let me know how that goes 🙂 Thanks

    #2617

    jorditruno
    Participant
    This reply has been marked as private.
    #2619

    Andrew Misplon
    Keymaster

    Nicely done! Thanks for making a few changes to the code I sent. For anyone else reading, the final code Jordi used to switch Meta Sliders based on language was:

    <?php
    
    	$currentlang = get_bloginfo( 'language' );
    
    	if ( is_front_page() ) {
    
    		if ( $currentlang=="es-ES" ) {
    			echo do_shortcode( "[metaslider id=66]" ); // Spanish
    		}
    
    		if ( $currentlang=="es-CA" ) {
    			echo do_shortcode( "[metaslider id=133]" ); // Catalan
    		}
    
    	}
    
    	else {
    		ultra_render_slider();
    	}
    
    ?>

    The reason I originally used single quotes in do_shortcode is that it allows the use of double quotes within the shortcode. Some shortcodes might have double quotes within the shortcode. For example, if you use LayerSlider instead of Meta Slider, the LayerSlider shortcode looks as follows:

    [layerslider id="1"]

    To use that shortcode within do_shortcode you need to use single commas:

    echo do_shortcode( '[layerslider id="1"]' );

    Ref: https://developer.wordpress.org/reference/functions/do_shortcode/

    If you run into any further challenges, please, let me know.

    All the best with your site 🙂

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

You must be logged in to reply to this topic.

Scroll to top