Skip Navigation

[Closed] Cannot embed Youtube video in Avada theme

This support ticket is created 3 years, 5 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.

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: Africa/Casablanca (GMT+01:00)

This topic contains 13 replies, has 2 voices.

Last updated by Jamal 3 years, 5 months ago.

Assisted by: Jamal.

Author
Posts
#2159591
Screenshot 2021-09-03 at 6.46.43 PM.png

Dear Sir/Madam,

My site installed the Avada theme, I have a custom field to post, I try to generate the embedded Youtube to page but failed.

Here is the code I place into the content, if I directly pass the Youtube like to a custom shortcode, the video is normally displayed, I add the second line the types field to confirm the field is correctly rendered.

I combine both shortcode the types fields but failed

[embed_video url="<em><u>hidden link</u></em>"]

{!{types field='recipes-video' output='raw'}!}{!{/types}!}

[embed_video url="{!{types field='recipes-video' output='raw'}!}{!{/types}!}"]

shortcode is

function ebz_embed_video($atts) {
    $re = '/(?im)\b(?:https?:\/\/)?(?:w{3}\.)?youtu(?:be)?\.(?:com|be)\/(?:(?:\??v=?i?=?\/?)|watch\?vi?=|watch\?.*?&v=|embed\/|)([A-Z0-9_-]{11})\S*(?=\s|$)/';
    preg_match_all($re, $atts['url'], $matches, PREG_SET_ORDER, 0);

    return sprintf("<iframe title='%s' src='<em><u>hidden link</u></em>' frameborder='0' allowfullscreen='allowfullscreen'></iframe>", 'TESTing', $matches[0][1]);

}
add_shortcode('embed_video', 'ebz_embed_video');
#2159925

Hello and thank you for contacting Toolset support.

Try to register the types of shortcodes inside the Toolset->Settings->Front-end Content->Shortcodes, and check again. If it does not help, you will have to build a solution that is not based on using shortcodes inside the arguments of other shortcodes.
For example, passing the URL through the $content instead of the $atts to the embed shortcode:

function ebz_embed_video($atts, $content) {
    $re = '/(?im)\b(?:https?:\/\/)?(?:w{3}\.)?youtu(?:be)?\.(?:com|be)\/(?:(?:\??v=?i?=?\/?)|watch\?vi?=|watch\?.*?&v=|embed\/|)([A-Z0-9_-]{11})\S*(?=\s|$)/';
    preg_match_all($re, $content, $matches, PREG_SET_ORDER, 0);
 
    return sprintf("<iframe title='%s' src='<em><u>hidden link</u></em>' frameborder='0' allowfullscreen='allowfullscreen'></iframe>", 'TESTing', $matches[0][1]);
 
}
add_shortcode('embed_video', 'ebz_embed_video');

And use it like this:

[embed_video]{!{types field='recipes-video' output='raw'}!}{!{/types}!}[/embed_video]

I hope this helps. Let me know if you have any questions.

#2160375
Screenshot 2021-09-04 at 9.28.00 AM.png
Screenshot 2021-09-04 at 9.30.40 AM.png

Dear Jamal,

Thanks for your reference, I tested but not work. I write two functions for testing

function ebz_embed_video_content($atts, $content) {
    return $content;
}
add_shortcode('embed_video_content', 'ebz_embed_video_content');


function ebz_embed_video($atts, $content) {
    $re = '/(?im)\b(?:https?:\/\/)?(?:w{3}\.)?youtu(?:be)?\.(?:com|be)\/(?:(?:\??v=?i?=?\/?)|watch\?vi?=|watch\?.*?&v=|embed\/|)([A-Z0-9_-]{11})\S*(?=\s|$)/';
    preg_match_all($re, $content, $matches, PREG_SET_ORDER, 0);
  
    return sprintf("<div class='scale-video'><iframe title='%s' src='<em><u>hidden link</u></em>' frameborder='0' allowfullscreen='allowfullscreen'></iframe></div>", 'TESTing', $matches[0][1]);
  
}
add_shortcode('embed_video', 'ebz_embed_video');

and I place below shortcode in a text block

[embed_video_content]{!{types field='recipes-video' output='raw'}!}{!{/types}!}[/embed_video_content]

[embed_video]{!{types field='recipes-video' output='raw'}!}{!{/types}!}[/embed_video]

Shortcode embed_video_content directly return the content of the {!{types field='recipes-video' output='raw'}!}{!{/types}!}

We can find the WP render {!{types field='recipes-video' output='raw'}!}{!{/types}!} to [types field='recipes-video' output='raw'][/types] and then pass to the function, that's why I can't grap the Youtube ID

If I try to put the toolset types field {!{types field='recipes-ingredient-en'}!}{!{/types}!} into Avada shortcode, the content can be rendered normally instead of [types field='recipes-ingredient-en'][/types]

[fusion_text columns="" column_min_width="" column_spacing="" rule_style="default" rule_size="" rule_color="" content_alignment_medium="" content_alignment_small="" content_alignment="" hide_on_mobile="small-visibility,medium-visibility,large-visibility" sticky_display="normal,sticky" class="" id="" margin_top="" margin_right="" margin_bottom="" margin_left="" font_size="" fusion_font_family_text_font="" fusion_font_variant_text_font="" line_height="" letter_spacing="" text_color="" animation_type="fade" animation_direction="up" animation_speed="1.0" animation_offset=""]

{!{types field='recipes-ingredient-en'}!}{!{/types}!}

[/fusion_text]
#2160393

fyi, there is the post hidden link

#2160407

Dear Jamal,

I can fix the issue by rendering the content in function once again but I am not sure whether it is the expected solution from Toolset, I worry the Toolset will fix this in coming update, then all my posts will be crashed.

function ebz_embed_video($atts, $content) {
    $content = do_shortcode($content);
    $re = '/(?im)\b(?:https?:\/\/)?(?:w{3}\.)?youtu(?:be)?\.(?:com|be)\/(?:(?:\??v=?i?=?\/?)|watch\?vi?=|watch\?.*?&v=|embed\/|)([A-Z0-9_-]{11})\S*(?=\s|$)/';
    preg_match_all($re, $content, $matches, PREG_SET_ORDER, 0);
  
    return sprintf("<div class='scale-video'><iframe title='%s' src='<em><u>hidden link</u></em>' frameborder='0' allowfullscreen='allowfullscreen'></iframe></div>", 'TESTing', $matches[0][1]);
  
}
add_shortcode('embed_video', 'ebz_embed_video');
#2160589

Well, we don't know yet, if this is an issue from Toolset, Avada, or from both. But, I believe that the last shortcode is the best solution because it does not rely on multiple environments(Toolset, Avada).

A better solution would be to directly get the information from the database instead of relying on another level of shortcodes:

function ebz_embed_video($atts, $content) {
    global $post; // the current post to display
    $video_url = get_post_meta( $post->ID, 'wpcf-recipes-video', true);

    $re = '/(?im)\b(?:https?:\/\/)?(?:w{3}\.)?youtu(?:be)?\.(?:com|be)\/(?:(?:\??v=?i?=?\/?)|watch\?vi?=|watch\?.*?&v=|embed\/|)([A-Z0-9_-]{11})\S*(?=\s|$)/';
    preg_match_all($re, $video_url, $matches, PREG_SET_ORDER, 0);
   
    return sprintf("<div class='scale-video'><iframe title='%s' src='<em><u>hidden link</u></em>' frameborder='0' allowfullscreen='allowfullscreen'></iframe></div>", 'TESTing', $matches[0][1]);
   
}
add_shortcode('embed_video', 'ebz_embed_video');

Then using directly like this:

[embed_video]

Note that I added the "wpcf-" prefix to "recipes-video". If the field is created by Toolset it will have this prefix at the database level.

#2160739

Dear Jamal,

Yes but I have 3 video links in the post. I rewrite the script as below

function ebz_embed_video($atts, $content) {
    global $post; // the current post to display
    $video_url = get_post_meta( $post->ID, $atts['v'], true);
 
    $re = '/(?im)\b(?:https?:\/\/)?(?:w{3}\.)?youtu(?:be)?\.(?:com|be)\/(?:(?:\??v=?i?=?\/?)|watch\?vi?=|watch\?.*?&v=|embed\/|)([A-Z0-9_-]{11})\S*(?=\s|$)/';
    preg_match_all($re, $video_url, $matches, PREG_SET_ORDER, 0);
    
    return sprintf("<div class='scale-video'><iframe title='%s' src='<em><u>hidden link</u></em>' frameborder='0' allowfullscreen='allowfullscreen'></iframe></div>", 'TESTing', $matches[0][1]);
    
}
add_shortcode('embed_video', 'ebz_embed_video');
[embed_video v="wpcf-recipes-video"]

Directly pass the custom field slug. Should we escalate to 2nd Tier to investigate the issue?

#2161113

That's a good solution that will handle more than one field.

We can escalate to 2nd Tier for further debugging, but we'll need to check some things before that, for example, we need to check if this will be reproduced on a clean install. Would you like to reproduce the issue on one of our test sites? If yes, I can create a new site and send you the credentials to install avada and reproduce the issue. Let me know if you would like that.

#2163607

Dear Jamal,

Sure, please try to create a new site. Do you want me to place the problem sample or the fixed sample?

#2165511

Sure, You can log into my test site with the following URL hidden link

Please install Avada, create a URL custom field and try to reproduce this issue.

#2172149

Oh, I don't have additional license of Avada

#2173203

I don't think you will need to activate a license. You may reproduce the issue without activating a valid license. If, on the other hand, that's not possible, please reach to the Avada theme and ask for an exceptional license. I am sure they can provide it to you so we can work on this together, then they can remove it.

The previous website has been deleted since then. The test sites remain available 7 days after the last admin login. I created a new site for you and I have already installed Avada on it. Please log into it with the following URL hidden link

#2174681

Dear Jamal,

Sorry your test site doesn't have the Toolset Views installed, I can't include the View shortcode.

#2174959

Sorry for the inconvenience. The site does have Toolset Blocks, which is basically the same as Toolset Views, except for one setting in Toolset->Settings->General(tab)->Editing experience.

I activated the Toolset Blocks plugin and enabled the legacy editor on it. Now you can build views, content templates, and archive templates using shortcodes.

If you would prefer to use Toolset Views, you can install it manually.

Looking forward to your reply.

The topic ‘[Closed] Cannot embed Youtube video in Avada theme’ is closed to new replies.