I have written some shortcode to be able to place the latest post excerpt anywhere on the page, but I got a problem that I have trying to solve for days now! And I can't find the reason why the get_the_excerpt() removes all p tags around text in other parts of the page. When I remove get_the_excerpt() from the code, it's no problem with the other text inside other shortcodes, but when I put i back, the problem is back! Please have a look at the code and tell me what I have done wrong or could improve! Thanks!

function show_posts() { global $post;
$html = "";
$extra_css = "";
$latestPosts = new WP_Query('cat=5&posts_per_page=1');
if($latestPosts->have_posts()): while($latestPosts->have_posts()): $latestPosts->the_post();

if (has_post_thumbnail()) {     
$extra_css = "has-thumbnail";}
$html = "<div class='wide'><article class='post {$extra_css}'>";
$html .= "<div class='post-thumbnail'>";
$html .= "<a href='" . get_the_permalink() . "'>" .     get_the_post_thumbnail(null,'thumbnail') . "</a>";  
$html .= "<div class='post-thumbnail-date'><h4>" . get_the_time('Y-m-d') . "</h4>   </div>";
$html .= "</div><!-- end post-thumbnail -->";
$html .= "<h3><a href='" . get_the_permalink() . "'>" . get_the_title() . "</a></h3>";
$html .= "<p class='post-info'>" . get_the_time('Y-m-d') . " | Av " . get_the_author() . "</p>";
$html .= "<p class='post-text'>" . get_the_excerpt() . "</p><p><a href='" . get_the_permalink() . "'> Läs mer...</a></p>"; 
$html .= "</article></div>";
// Error message
return $html;
  • I cannot reproduce your issue. Are you filtering the excerpt in any way Jul 19, 2015 at 8:25
  • Thanks for your answer! No, I'm not filtering it. I just discovered that the p tags are OK within the post excerpt but gone on all other parts of the page. I'm not sure what to do to solve this :(
    – 3D-kreativ
    Jul 19, 2015 at 8:30


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.