I am having an issue with a plugin that I work on for WordPress. It should embed YouTube, Vimeo, SoundCloud and more based on the URL provided by the user.
The embed in WP should be very easy like:
[embed width="640" height="480]http://www.youtube.com/watch?v=dpVUIwrNLoo[/embed]
The thing is that this is not working at all.
echo do_shortcode('[embed width="640" height="480]http://www.youtube.com/watch?v=dpVUIwrNLoo[/embed]');
Thank you,
Marius
Why not use wp_oembed_get ?
Your code would be like:
$videourl = 'http://www.youtube.com/watch?v=dpVUIwrNLoo';
$htmlcode = wp_oembed_get($videourl);
echo $htmlcode;
Related
I am having a weird issue.
Normally when you paste a youtube video the video will embed properly automatically. However when I paste a link into the visual view I can play and see the embedded video in the EDIT view, but on preview or publish it echoes out the link without embedding it as plain text.
So far I have tried disabling all plugins (except Advanced Custom fields)
Using the [embed] shortcode
Changing the youtube links from http to https
What does work is pasting the embed code from Youtube, or writing <iframe> in the text view.
It also works fine to paste and embed when I change theme
For me the issue was I was using
<?php echo get_the_content(); ?>
Instead of
<?php the_content(); ?>
As per the Wordpress Codex:
An important difference from the_content() is that get_the_content()
does not pass the content through the the_content filter. This means
that get_the_content() will not auto-embed videos or expand
shortcodes, among other things.
https://developer.wordpress.org/reference/functions/get_the_content/#:~:text=An%20important%20difference%20from%20the_content()%20is%20that%20get_the_content()%20does%20not%20pass%20the%20content%20through%20the%20the_content%20filter.%20This%20means%20that%20get_the_content()%20will%20not%20auto%2Dembed%20videos%20or%20expand%20shortcodes%2C%20among%20other%20things.
Use the [video] short code instead. It is incorporated in the Wordpress core nowadays. Go to this link for more info: https://codex.wordpress.org/Video_Shortcode
For example:
[video width="640" height="360" src="/wp-content/uploads/files/movie.mp4"]
May this not work in a custom theme, then you want to look at how the content of the post is being processes. You may need to apply the the_content filter to the post content variable like this:
apply_filters('the_content', $post->post_content);
I want to add mp4 video to my page, but shortcode [video] not workig. I see only string in frontend with:
[video width="640" height="360" mp4="http://localhost:8080/CC/wp-content/uploads/2015/05/movie.mp4"]
Where is the problem ?
Thanks for help.
Try putting the closing shortcode tag [/video] like this
[video width="640" height="360" mp4="http://localhost:8080/CC/wp-content/uploads/2015/05/movie.mp4"][/video]
its shoudnt be a requirement but just in case try it let us know.
You neglected the short-code. You wrote mp4 instead of src
Code corrected:
[video width="640" height="360" src="http://localhost:8080/CC/wp-content/uploads/2015/05/movie.mp4"]
In my case, I was seeing a normal link to the video instead of the video element.
Removing the playsinline attribute from the video tag (which had been added via a PHP filter in my functions.php file) and making sure the video format was correct fixed the issue for me.
I am trying to generate some embeddable iframe code so a user can include the code on a blog to display content I'm planning to deliver. Right now the content I'm trying to deliver is just a website. I am trying to use the following code on a Wordpress blog:
<iframe width="420" height="315" src="http://www.cnn.com" frameborder="0"></iframe>
However when the page is viewed Wordpress simply outputs a link for "http://www.cnn.com" based on the following html.
http://www.cnn.com
That said, if I use Youtube generated iframe code, the iframe loads fine. For example:
<iframe width="420" height="315" src="http://www.youtube.com/embed/_OBlgSz8sSM" frameborder="0" allowfullscreen></iframe>
results in:
<iframe class='youtube-player' type='text/html' width='420' height='315' src='http://www.youtube.com/embed/_OBlgSz8sSM?version=3&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1&wmode=transparent' frameborder='0'></iframe>
Any idea what Youtube is doing to enable this functionality or more generally how to get my simply iframe to work.
I don't know why you get an anchor instead of the iframe, but I know that google don't want their homepage in iframes. If you would have an iframe with the src http://www.google.com, you would see an empty iframe. Also see this example.
=== UPDATE ===
Wordpress prohibits iframes with few exceptions. Probably you can handle it with shortcodes. Try adding following untested code into the functions.php in your theme.
// [iframe src="www.cnn.com"]
function iframe_func($atts) {
extract(shortcode_atts(array(
'src' => 'default'
), $atts));
return '<iframe src="{$src}"></iframe>';
}
add_shortcode('iframe', 'iframe_func');
Now you can add [iframe src="www.cnn.com"] in the article editor in the wordpress admin.
Creating a shortcode is the way I get around this problem. It bypasses the WYSIWYG editor and puts the html in the page.
I would approach it like this.
Add this to your functions.php file:
function add_iframe($atts) {
extract(shortcode_atts(array(
'src' => '/'
), $atts));
$theframe = '<iframe src="'.$src.'" width="420" height="315" frameborder="0"></iframe>';
return $theframe;
}
add_shortcode('iframe', 'add_iframe');
Useage:
Add [iframe src=http://thesiteyouwanttoshow.com] to the content where you want the iframe to show.
If you are loading your own web page within the iframe remember that most hosted solutions will have xFrame options set to SAMEORIGIN, so no matter what you change in Wordpress, the page will still not render as it is being blocked by the target website.
I spent hours with this problem so hopefully if you are having this issue you will the target website as well. If you are hosting a solution on rails the answer I found is here and a website that will definitely load in Wordpress can be found here, so feel free to use that endpoint as a test.
Google uses the X-Frame-Options header (set to SAMEORIGIN) to prevent you from placing it in an iframe. Getting around this would require the user to use a browser that doesn't support X-Frame-Options.
Unfortunately the major search engine sites such as google and yahoo (bing excluded) don't allow for iframe embedding since they offer a plethora of APIs and integration options. So there is really no real way for you to do this. If you are not planning on embedding google as your iframe source then you should be in the clear with the current code that you have in place. Try it out and just change the source to something else - google will not show up in its place. If you want a search engine there unfortunately it is with horror that I say that bing is the only one that works.
Hope this helps!
So in recap - Google does not embed in iframe, but other content that you produce should based on your coding:
example:
<iframe width="420" height="315" src="http://www.uncrate.com" frameborder="0"></iframe>
http://jsfiddle.net/pKby8/
The Anchor that you get is a result of the xFrame option. When it connects to the google servers the servers kick back a cute response hinting that you should link to them instead of iframe.
I would create a WordPress short_code that would insert your iFrame in the output. I think by adding the iFrame code directly in the post box wordpress is changing it.
http://codex.wordpress.org/Shortcode_API
I've a wordpress blog for my website and added facebook comment for that. It shows the option to enter the comment using facebook account. But that doesn't show the comments from users.
Any idea about that will be really helpful.
try this plugin
facebook-comments-for-wordpress.3.1.3
only you have to write the following shortcode wherever you want comments to be displayed:
<?php if (function_exists('facebook_comments')) facebook_comments(); ?>
I have implemented it and it works fine.
Is there anything need to enable for shortcode to work in Wordpress 3.0? I have tried some short codes and none of them working as expected.
regards - dj
If its a template file you are trying to put them into you will need to put the code into a function and display it like:
<?php echo do_shortcode( '[contact-form-7 id="448" title="Contact"]' ); ?>
I am guessing you have it all sorted by now though as I have just checked when this was posted.
Short codes are as simple or as complex as you intend them to be. Also they can solve some pretty annoying problems and add a lot of functionality for your users. One thing I always use a short code for is embedding YouTube videos and media of the same format.
Here are some links that may help you:
Google Maps Short Code - by Chris Coyier # http://www.digwp.com/
Short Code API - WordPress Codex page about
short codes
Plus make sure you call the following function
the_content()
to output your content