Embed shortcodes and oEmbed not working on Wordpress - wordpress

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);

Related

How to add custom content in sidebar of each Wordpress post?

I want to integrate specific text (text, links, images) making reference to specific sentences of my blog post.
Is it possible to do it with code or using a plugin ?
I send you a sketch :
This is the sketch
That is common need and often Aside in WordPress is talked for it. There are WP plugins like Aside Widget, Custom Sidebars for ordinary needs. But if you need too much custom stuff like my website's "About this Article" sidebar widget - https://thecustomizewindows.com/2016/09/limitations-of-openvz-virtualization-to-guest-cloud-server-vps/ then it is better to use
Otto's this plugin to use PHP in text widget - https://wordpress.org/plugins/php-code-widget/ and use PHP. In my case, rest is PHP code like this on sidebar (I can use shortcode too) :
<?php if(is_single()) : ?>
<h3>About This Article</h3>
<strong>Title:</strong> <?php echo get_the_title(); ?><br />
Published on: <?php the_time('Y-m-d') ?>
<br />
...
// rest of the code
<?php endif; ?>
Obviously you can call post image thumbnail with WordPress function.
As you need specific text, you may think about combining Pull Quote Plugin or Aside Widget to mark the specific like and echo it with PHP.
As other options -- you can use CSS3 to automatically select first line, first paragraph, second sentence. You can use Javascript to conditionally mark.
Best possible customisation I saw is on BMJ's sidebars. They use Drupal, not WordPress. BMJ has beautiful sidebar -- (as example) - http://www.bmj.com/content/355/bmj.i4924 Drupal has description of the work - https://www.drupal.org/node/1557636 Sadly I lack idea about Drupal. I tried a lot behind using WordPress for academic purpose.

WordPress -Why are shortcodes being ignored in my custom post type?

I am using Visual Composer which works great on my posts and pages, however, when I view a custom post type that I created using Visual Composer, all of the shortcodes are ignored so the page looks something like the following...
[vc_row][vc_column][vc_column_text]I am a text box.[/vc_column_text][/vc_column][/vc_row]
My cpt template uses the wordpress loop <?php the_content(); ?> and shotcodes are ignored. My other page templates also use <?php the_content(); ?> but all the Visual Composer shortcodes work perfectly.
I tried replacing my cpt template with my default page template and the shortcodes were still ignored so I don't think it's a template issue because I concluded that using the default page template for a page post works perfectly but using the same template for a cpt post does not work and ignores the shorcodes.
I don't know what is causing this. Any help is appreciated.
Maybe you missed the wp_head(); at the header or wp_footer at the footer

Opening Wordpress Gallery from a link

Is it possible to open a wordpress gallery using an anchor tag so that the gallery appears on the same page in a lightbox? I cannot figure out how to do so. It seems like it should be such a simple thing to do but I have tried various plug ins and cannot work out a simple solution.
first, install this plugin
https://wordpress.org/plugins/anything-popup/
Then go to setting->anthing-pop there will be a shortcode http://awesomescreenshot.com/03561dd759
then click to edit it and put the [galley] shortcode
http://awesomescreenshot.com/09261ddfc0
http://awesomescreenshot.com/0ae61ddmb5
Now use the shortcode on click see screenshot
http://awesomescreenshot.com/0de61dej39
you can use the shortcode into post or page or in file like this
<?php echo do_shortcode('[AnythingPopup id="1"]'); ?>
thanks

Wordpress (Pods) oEmbed Items

I'm using the fantastic Pods plugin to extend Wordpress's basic content types with a few custom ones. I've build an advanced custom type which means I don't get the automatic oEmbed support built into the native page/post types. I've structured it so my custom content type has a pod page using a PHP page template and I have the oEmbed option enabled for my WYISWYG fields that can embed videos.
I found this post which seems to indicate that a basic apply_filter function should automatically handle any embeds but I can't seem to get it to work. I'm a bit new to filters. The code I tried is below:
<?php
// Fetch body field content from $pods object
$mycontent = $pods->field('field_body');
$output = apply_filters('oembed_dataparse', $mycontent);
echo $output;
?>
I tried a variety of different filters such as the_content and others but none seemed to work. I believe it may be a scoping/conflict issue with Pod pages since even writing out entire iFrame embed code into the template won't work but only displays an empty iFrame. The global oembed function does the same, i.e.
$videourl = 'http://www.youtube.com/watch?v=dQw4w9WgXcQ';
$htmlcode = wp_oembed_get($videourl);
echo $htmlcode;
In the context of the page template will output:
<iframe width="500" height="375" frameborder="0" allowfullscreen="" src="http://www.youtube.com/embed/dQw4w9WgXcQ?feature=oembed">
<html>
<head>
</head>
<body>
</body>
</html>
</iframe>
field() gets the value of the field, display() gets the output of the field (ran through any related filters / functions the field is configured to run through).
$mycontent = $pods->field('field_body');
should be
$mycontent = $pods->display('field_body');
For more information, see http://pods.io/docs/field/ vs http://pods.io/docs/display/
Calling apply_filters('oembed_dataparse', $mycontent) is incorrect since this meant to add functionality for processing other data types (photo, video etc) not catered for by default. What you want to do is mimic how WordPress does the embedding. I haven't tested the code below, but it seems to me the way to go about triggering the embed functionality:
global $wp_embed;
$mycontent = $pods->field('field_body');
$output = $wp_embed->autoembed($mycontent);
echo $output;

wordpress <!--more--> not rendering a link

I am using the <!--more--> tag in my wordpress copy to create an excerpt from the main content and also echo a link, however it is totally disregarding this tag and just posting the full article, below is hope I am implementing it in my templates,
<?php the_content("Read more about this article..."); ?> am I doing something wrong? Currently it is showing the while post when I use the above code, however it is my belief that it should only only show everything above the <!--more--> tag?
As per the official WordPress support site:
From the use of your PHP code, it looks like you want to use the more tag on pages. More works with blog posts but not pages. Please add the following code to your document above your PHP line you provided to make it work:
<?php
global $more;
$more = 0;
?>
Also, be sure that you are not simply in preview mode and that you have actually published the article and previewed it:
[T]he more tag is not displayed in post previews, since previews display
posts in entirety, but the more tag will appear once the post has been
published.
Perhaps you are using custom page template to display archives. "More" tag doesn't work in pages. If you want to turn it on in Pages...
<?php the_content("Read more about this article..."); ?>
you should use the code like this if you wanna show the to work in a page
<?php
global $more;
$more = 0;
the_content("Read more about this article...");
?>

Resources