jorditruno Oct 31, 2015 · 11:31 am #2615 Good morning,
I’m working for the first time with ULTRA theme. I think it is a really good theme.
I have created a Child Theme to work in.
I have created Two Sliders for the HOME page
Version 1 in the spanish language, with the shortcode [metaslider id=66]
Version 2 in the catalan language, with the shortcode [metaslider id=133]
I work with the plugin qTranslate to translate and to swicht the languages. All goes fine just here.
But in the Display Page Meta Slider I can ONLY place one version of the slider.
I think that I can change something in the metaslider.php archive, but I dont know enought to code it.
…Something like
if the switch is “es” then place the [metaslider id=66]
if the switch is “ca” then place the [metaslider id=133]
Maiby can I place the code in the funtions.php of the child theme?
Can you help me?
Thank you in advance…
Jordi
Andrew Misplon Puro Oct 31, 2015 · 1:59 pm #2616 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
jorditruno Nov 2, 2015 · 1:45 am #2617 This reply has been marked as private.
Andrew Misplon Puro Nov 2, 2015 · 8:44 am #2619 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 🙂