I have written a small function to display the latest video on my startpage. The function itself works just fine. The only problem is, that wordpress keeps inserting an opening
tag at one place of the code.
Here is my function:
The output I am having a problem with is this:
I have tried removing the wp-autop filter several ways but it simply wont work. And even after using google for over two hours now i cant find a solution.
Code:
<p>
Here is my function:
Code:
function video_start() {
// the query
$the_query = new WP_Query(array('post_type'=>'page','post_parent'=>'17','order'=>'ASC','orderby' => 'date','posts_per_page'=>1));
// The Loop
if ( $the_query->have_posts() )
{
while ( $the_query->have_posts() )
{
$the_query->the_post();
if ( has_post_thumbnail() )
{
$picid = get_post_thumbnail_id($post_id);
$alt_text = get_post_meta($picid , '_wp_attachment_image_alt', true);
$string .= '<div class="featured-start">';
$string .= '<a href="' . get_the_permalink() .'" class="b-link" rel="bookmark">';
$string .= '<h2 class="mar-bot">Latest Video</h2>';
$string .= '<img src="'.wp_get_attachment_url(get_post_thumbnail_id($post_id)).'" class="img-responsive" alt="'.$alt_text.'" />';
$string .= '<p>'.get_the_title().'</p>';
$string .= '<div class="orange-button">Watch Video</div></a></div>';
}
}
}
else
{
// no posts found
}
$string .= '<div class="clear"></div>';
return $string;
/* Restore original Post Data */
wp_reset_postdata();
}
// Add a shortcode
add_shortcode('video_startpage', 'video_start');
// Enable shortcodes in text widgets
add_filter('widget_text', 'do_shortcode');
The output I am having a problem with is this:
Code:
<div class="featured-start">
<a href="http://www.kundenwebseite.inweco.de/videos/pet-project-09-part-1/" class="b-link" rel="bookmark"><br />
<h2 class="mar-bot">Latest Video</h2>
<p><img src="http://www.kundenwebseite.inweco.de/wp-content/uploads/2015/11/pet-project-2009-part-1.jpg" class="img-responsive" alt="" />
<p>Pet Project 09 &#8211; Part 1</p>
<div class="orange-button">Watch Video</div>
<p></a></div>
<div class="clear"></div>
I have tried removing the wp-autop filter several ways but it simply wont work. And even after using google for over two hours now i cant find a solution.