Related Docs

Did not find what you're looking for? Search the complete TukuToi Software Documentation

ShortCode

Make iFrames Multilingual

By default iFrames are not multilingual because they are HTML code. but there’s a way to easily make them multilingual without too much hassle.


function my_embed( $atts ) {
	$a = shortcode_atts( array(
		'src' => 'default_url_goes_here',
	), $atts );

	$awesome_iframe='<iframe width="100%" height="300" scrolling="no" frameborder="no" allow="autoplay" src="' . $a[src] . '"></iframe>';
	return $awesome_iframe;
}
add_shortcode( 'custom_iframe', 'my_embed' );

The code goes into your active theme’s function.php file and can be used by adding the “src” parameter in the shortcode from the “src” parameter in the iframe code you want to use.

Example

If the iFrame looks like this:

<iframe width="100%" height="300" scrolling="no" frameborder="no" allow="autoplay" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/playlists/1075752043&color=%23ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true&visual=true">

The shortcode will look like this:

[custom_iframe src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/playlists/1075752043&color=%23ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true&visual=true"]

Now all you have to do is register the shortcode to be translated with WPML using this guide: https://wpml.org/documentation/support/language-configuration-files/#page-builder-content

It would end up looking like this and you can add it in WPML > Settings > Custom XML Configuration:

<wpml-config>
   <shortcodes>
        <shortcode>
            <tag>custom_iframe</tag>
            <attributes>
                <attribute>src</attribute>
            </attributes>
        </shortcode>
   </shortcodes>
</wpml-config>

And that’s it!

You can translate iFrames now.