Skip Navigation

[Resolved] Add an iframe to Elementor using dynamic URL

This support ticket is created 4 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 1.50 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 3 replies, has 2 voices.

Last updated by Greig Neilson 4 years, 4 months ago.

Assisted by: Waqar.

Author
Posts
#1396887

I want to use a Types field to generate a URL for an iframe, and display it within and Elementor template.

I can display the iframe successfully using the Elementor shortcode widget. But when I try and make it dynamic it fails.

I tried following the advice in this ticket but I can't fully understand the solution: https://toolset.com/forums/topic/how-to-add-dynamic-url-to-src-within-iframe/

Many thanks!

#1397223

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Greig,

Thank you for contacting us and I'd be happy to assist.

Can you please share temporary admin login details along with the link to a page where this iframe's code can be seen? I'll be in a better position to guide you accordingly.

Note: Your next reply will be private and though no changes will be made on your website, please make a complete backup copy, before sharing the access details.

regards,
Waqar

#1401685

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Greig,

Thank you for sharing the admin access.

The way Elementor's shortcode widget processes the before and after content, it converts the HTML code for the iframe into special characters or HTML entities.

Also using a text widget to mix the field's shortcode and HTML also doesn't work, since the builder seems to strip the iframe code.


<iframe src="[types field='website-theme-demo-url' output='raw'][/types]"></iframe>

An alternative can be to register a custom shortcode that can convert the field's data into an iframe tag and return the output.

Example:


add_shortcode( 'convert-field-to-iframe', 'convert_field_to_iframe_func');
function convert_field_to_iframe_func($atts) {
	$a = shortcode_atts( array(
		'field' => '',
		'width' => '300',
		'height' => '300'
	), $atts );

	$field_URL = types_render_field($a['field'], array("output" => "raw"));

	if(!empty($field_URL)) {
		return '<iframe src="'.$field_URL.'" height="'.$a['height'].'" width="'.$a['width'].'"></iframe>';
	}
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through active theme's "functions.php" file.

After that, you can use this shortcode in the Elementor template's text widget like this:


[convert-field-to-iframe field="website-theme-demo-url" width="400" height="600"]

Feel free to adjust the values for field, width, and height, as needed.

I hope this helps and please let me know how it goes.

regards,
Waqar

#1401751

Thanks, Waqar, works perfectly!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.