I am using the code below to execute video shortcode on my WordPress website but some pages already contain manually added video which will cause duplicate when i use the code.
How can include a check if the page already contain a YouTube embedded iframe or video link and exclude pages which already have videos, here is what i have below:
if (is_single() && in_category(1) )
{
echo '<h4 class="post-title entry-title">Video</h4>' ;
echo do_shortcode( '[yotuwp type="keyword" id="'.get_post_field( 'post_title', $post_id, 'raw' ).'" player="mode=large" template="mix" column="1" per_page="1"]' );
}
I want to include youtube link check here:
if (is_single() && in_category(1)
Here is what i am able to find Here but this scans the requested url instead of the content on it:
<?php
if (stripos($_SERVER['REQUEST_URI'],'tout') == true && stripos($_SERVER['REQUEST_URI'],'dedans') == true)
{echo '<div class="clear"></div><a href="http://www.example.com/cakes/" class="btn"> >> View all Cakes</a>';}
?>
Since you already have the $post_id
I suggest you get the Post object and do a regular expression match for 'youtube' or the short URL version 'youtu.be'. See sample code:
$post = get_post($post_id);
$content = apply_filters('the_content', $post->post_content);
if (is_single() && in_category(1) && !preg_match('/youtu\.?be/', $content)) {
echo '<h4 class="post-title entry-title">Video</h4>';
echo do_shortcode('[yotuwp type="keyword" id="' . get_post_field('post_title', $post_id, 'raw') . '" player="mode=large" template="mix" column="1" per_page="1"]');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With