Youtube url parameter ?playlist=[video_id's] no longer working - youtube-iframe-api

On my website, we have product pages where employees can put in youtube video id's into the CMS. Those id's are saved into the database, and later pulled out in the array $videos.
<? php
$youtube_url[0] = "https://www.youtube.com/embed/?rel=0&modestbranding=1&playlist=";
$youtube_url[0] .= implode(",", $videos);
?>
<iframe width="580" height="315" src=<?= $youtube_url[0] ?> frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
This creates a an hoc playlist out of the Youtube IDs listed after playlist= and had been working properly for nearly a year until sometime within the last week or so. Did something change? Is the ?playlist= parameter broken?

It works fine if you define the first id as the video:
Like: https://www.youtube.com/embed/qYodWEKCuGg?playlist=uOtdsJKsDc0,b-IEVMwBEfo
Code:
<?php
$videos = [
'qYodWEKCuGg',
'uOtdsJKsDc0',
'b-IEVMwBEfo'
];
$url = 'https://www.youtube.com/embed/'.$videos[0].'?playlist=';
array_shift($videos);
$url .= implode(",", $videos);
?>
<iframe width="580" height="315" src="<?= $url ?>" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
whilst this won't work:
https://www.youtube.com/embed?playlist=qYodWEKCuGg,uOtdsJKsDc0,b-IEVMwBEfo

Related

Apply autoplay to iframe-video via browserside css-injection

I would like to autoplay all videos on a specific domain. These are embedded via iframe For this I think I can use a browser-addon like "Page Manipulator" and inject CSS or Javascript.
Page original:
<div class="box playa">
<div id="myVideo" data-vimeo-initialized="true">
<div style="padding:56.25% 0 0 0;position:relative;">
<iframe src="https://player.vimeo.com/video/66...?h=63..&title=0&byline=0&app_id=12.." frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen="" style="position:absolute;top:0;left:0;width:100%;height:100%;" title="...m4v" data-ready="true"></iframe></div></div>
<script src="https://player.vimeo.com/api/player.js"></script>
<script>
var options = {
url: "https://vimeo.com/66..",
width: 800,
responsive: true,
byline: false,
title: false,
}; ...
And I tried to inject this CSS but did not get any changes:
#iframe {
autoplay:1
}
What do I need to inject to autoplay all vimeo-videos? Video say, I have to use a src-Link like this (see end)
<iframe src="https://player.vimeo.com/video/66..=63..&title=0&byline=0&app_id=12..&autoplay=1"
This works, but I dont know how to inject this code "autoplay=1" in every iframe-src at the end...

Show another website in iFrame

I am trying to show a website on iFrame tag, it is working fine only at the landing page and while clicking on any page links it redirects me to the live website. I don't want it to redirect it to the live website. I am using the following code in php.
<iframe src="demo1.php" frameborder="0" >
</iframe>
<?php
$site = array('http://anusha.bluethink.in/b4bstaging/','http://anusha.bluethink.in/b4bstaging/personalised-balls.html');
$i=0;
foreach($site as $n) {
echo file_get_contents($site[$i]);
$i++;
}
?>

How to add multiple ads in Facebook Instant Articles using wordpress plugin?

I want to display multiple ads on Facebook instant articles. I found this code, which I tried manually and its working.
<section class="op-ad-template">
<!-- Ads to be automatically placed throughout the article -->
<figure class="op-ad">
<iframe src="https://www.mywebsite.com/ss;adtype=banner300x250&adslot=1" height="300" width="250"></iframe>
</figure>
<figure class="op-ad op-ad-default">
<iframe src="https://www.mywebsite.com/ss;adtype=banner300x250&adslot=2" height="300" width="250"></iframe>
</figure>
<figure class="op-ad">
<iframe src="https://www.mywebsite.com/ss;adtype=banner300x250&adslot=3" height="300" width="250"></iframe>
</figure>
</section>
Now I am trying to make it possible via Facebook Instant Article Plugin. I didn't find any setting option for these type ads.
I tried to search on google and can't find anything except this:
https://developers.facebook.com/docs/instant-articles/sdk/transformer-rules
Please help me!
A. How to add multiple ads using FB INSTANT ARTICLE PLUGIN in wordpress?
B. How to add different codes using FB INSTANT ARTICLE PLUGIN in wordpress?
You can do this by adding the instant_articles_transformed_element filter, in order to modify the header accordingly.
This is generally used when placing Facebook Audience Network units, but if your manual code worked, the following code should work, although you might need to play around with the query vars. Add to functions.php the following:
At the top of functions.php, add this:
use Facebook\InstantArticles\Elements\Ad;
And then:
/**
* Adds multiple units to the Instant Article
*
* #param Instant_Articles_Post $article
*
* #return Instant_Articles_Post
*/
add_filter('instant_articles_transformed_element', function ($article) {
// Create the base ad
$ad = Ad::create()
->withWidth(300)
->withHeight(250)
->enableDefaultForReuse();
// Retrieve the header
$article->getHeader()
// Add the first ad
->addAd(
$ad->withSource(
// This creates the URL https://www.mywebsite.com/ss;adtype=banner300x250;adslot=1
add_query_arg(
array(
'adtype' => 'banner300x250',
'adSlot' => '1',
),
'https://www.mywebsite.com/ss'
)
)
)
// Add the second ad
->addAd(
$ad->withSource(
// This creates the URL https://www.mywebsite.com/ss;adtype=banner300x250;adslot=2
add_query_arg(
array(
'adtype' => 'banner300x250',
'adSlot' => '2',
),
'https://www.mywebsite.com/ss'
)
)
)
// Add the third ad
->addAd(
$ad->withSource(
// This creates the URL https://www.mywebsite.com/ss;adtype=banner300x250;adslot=3
add_query_arg(
array(
'adtype' => 'banner300x250',
'adSlot' => '3',
),
'https://www.mywebsite.com/ss'
)
)
);
return $article;
});
With that code, the plugin will take care of the rest, and it will automatically add the following code to the head section:
<meta property="fb:use_automatic_ad_placement" content="enable=true ad_density=default"/>
It will also add the following right before closing the header:
<section class="op-ad-template">
<figure class="op-ad op-ad-default">
<iframe src="https://www.mywebsite.com/ss?adtype=banner300x250&adSlot=1" width="300" height="250"></iframe>
</figure>
<figure class="op-ad">
<iframe src="https://www.mywebsite.com/ss?adtype=banner300x250&adSlot=2" width="300" height="250"></iframe>
</figure>
<figure class="op-ad">
<iframe src="https://www.mywebsite.com/ss?adtype=banner300x250&adSlot=3" width="300" height="250"></iframe>
</figure>
</section>

Twig add attribute with value in a variable

Using Drupal 8
I want to print out a field's content into the src attribute. I have the following template for my view:
<div class="videoWrapperHD">
<iframe width="560" height="315" src="{{ rows[0].content | raw }}"
frameborder="0" allowfullscreen>
</iframe>
</div>
But the iframe gets filled with my own site's "Page Not Found" page instead of the Youtube Video because Twig prints out a whole lot of debug comments before and after printing the variable rows[0].content.
Is it possible to disable the debug comments for a specific field? I don't want to have to be disabling/enabling debug to make sure it works as expected.
I also tried using {{ attributes.setAttribute('src', {{ rows[0].content }} ) }} , but no dice.
Another failed attempt was:
{% set iframe_src = rows[0].content %}
<div class="videoWrapperHD">
<iframe width="560" height="315" {{ attributes.setAttribute('src', iframe_src) }}
frameborder="0" allowfullscreen></iframe>
</div>
My last idea was this:
{% set url = rows[0].content | raw %}
{% set iframe_src = 'src=' ~ url %}
<div class="videoWrapperHD">
<iframe {{ iframe_src }} ></iframe>
</div>
But it prints out src=Array
try this
in your .theme
function your_theme_preprocess_field(&$variables, $hook) {
switch ($variables['element']['#field_name']) {
case 'field_iframe_src':
$variables['iframe_src'] = $variables['items'][0]['content']['#context']['value'];
break;
}
}
in your twig
<iframe width="560" height="315" src="{{ iframe_src|raw}}"
frameborder="0" allowfullscreen>
</iframe>
Sounds like something that would have to be done in the preprocessor. If you grab it from the node object, instead of the content array it shouldn't get all that debug nonsense.
You should also make sure that your URL isn't doing something evil... if you only expect youtube videos you should do some checking to make sure that that is what you get from the content.
https://api.drupal.org/api/drupal/core%21modules%21node%21node.module/function/template_preprocess_node/8.2.x
See $node, find the value, sanitize/double check it's value, then set it to $variables['variable_name'] and you should be able to use it in twig with {{variable_name}}
The answer is in another question, I'm pasting it here in case that one gets deleted. The author of the following answer is #4k4
field.content is the rendered field. And in views that means it is no longer a render array, but the finally rendered markup. So this is very problematic to use it as a class name, not only because of twig debug.
Better use the row data, where you find the entity object with the field data from the database. Use clean_class to escape it for using it as a class name:
{{ row._entity.field_myfield.value|clean_class }}

How to get a iframe from wordpress post content

I have post with iframe like
<iframe src="//player.vimeo.com/video/71287888?byline=0&portrait=0" width="900" height="450" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
Li Europan lingues es membres del sam familie. Lor separat existentie es un myth. Por scientie, musica, sport etc, litot Europa usa li sam vocabular.
In the above the i-frame need to be differentiate from th content. As i like only
<iframe src="//player.vimeo.com/video/71287888?byline=0&portrait=0" width="900" height="450" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
So, how can i get the video iframe for the content.
I was able to get the the solution myself.
Here's the code
$vcont = eevee_content(40);
$videoframe = explode("</iframe>",$vcont);
echo $videoframe[0]."</iframe>";
By the eevee_content function i was able to get the content. After that it explodes the string to an array and we get the iframe by using $videoframe[0]

Resources