Novice here, please help. I made a dynamic page with Custom Post Type UI plugin where the user can input news updates. The information to be filled are date, title, and a link (a clickable button that will bring the user to an external web page).
On page-news.php:
<!-- NEWS LINKS -->
<div class="row py-5">
<?php
$loop = new WP_Query(array(
'post_type' => 'news',
'order_by' => 'post_id',
'order' => DESC
));
?>
<?php while($loop->have_posts()) : $loop->the_post(); ?>
<div class="col mb-2 mt-3">
<?php
if(has_post_thumbnail()) {
the_post_thumbnail('full');
}
?>
</div>
<div class="col-md-12">
<p class="mb-1"><small><?php the_field('news_date'); ?></small></p>
<h5><?php the_title(); ?></h5>
<a href="<?php the_content(); ?>" class="newsLink pl-2 mb-5 btn btn-sm bg-red text-white"
target="_blank">Read more</a>
</div>
<?php endwhile;
wp_reset_query(); ?>
</div>
The Problem:
Wordpress 5 displays an iframe and a blockquote automatically:
<blockquote class="wp-embedded-content" data-secret="eCcoDo7d81"><p><a href="/">1</a></p></blockquote>
<iframe title="“1” — Example" class="wp-embedded-content" sandbox="allow-scripts" security="restricted" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);" src="" data-secret="eCcoDo7d81" width="600" height="338" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
What I did to fix it:
On functions.php I added this code
/* Remove WP auto embed */
function remove_embed ($content) {
if ( is_page('bac-in-the-news')) {
$content = preg_replace('/@<iframe[^>]*?>.*?</iframe>@siu/', '', $content); // removes iframe
}
return $content;
}
add_filter ('the_content', 'remove_embed');
A new problem:
The iframe and blockquote did not displayed anymore but I'm facing a new problem. The anchor tag does not display the href's content.
<a href="" class="newsLink pl-2 mb-5 btn btn-sm bg-red text-white" target="_blank">Read more</a>
Where did I do wrong? Why it can't display the_content() anymore? Please point me in the right direction. Thanks in advance.
- Edit: Here's the picture of the custom post type that I created. The body section is where the user should post the link.