functions – Replace word in “the_content” only for index.php

I have some posts with video tag that contains autoplay (they should autoplay when you access the post page).

I am using the the_content to show these videos on index page.

The problem is that when you access the home page, all the videos start playing.

I have used the following function to remove it:

function replace_ap($text){
    $replace = array(
        'autoplay=""' => ''
    $text = str_replace(array_keys($replace), $replace, $text);
    return $text;
add_filter('the_content', 'replace_ap');

but now the “autoplay” attribute is removed from the post pages also.

How can I remove it only from the index ?

My thought was to create a function that gets the content and add the filter to this function, then call it from index.php instead of “the_content”, but I don’t know how or if it’s possible

Thank you!

custom post types – Cannot display the_content() after removed WordPress 5’s auto embed feature (iframe & blockquote)

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">
  $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">
    if(has_post_thumbnail()) {

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

  <?php endwhile;
  wp_reset_query(); ?>

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.

the content – does wp work the_content (); accept another label inside

I want to place another PHP tag inside the_content () is it possible in one way or another?

ID, 'wp_custom_attachment', true );

      $custom_attach = get_post_meta( get_the_ID(), 'wp_custom_attachment', true );

     $name = 'button';

if ( ! empty( $custom_attach ) ) {

    echo '';
    echo ''.$name.'';
    echo '';
); ?>

filters – the_content () does not display the full post

When I use the_content () in the template php file, it prints the_excerpt () instead of the full message content.

I tried to remove all filters with


But it still displays the extract.

I found the solution to display the full content of the message by retrieving it directly from the database.

$post_data = get_post(get_the_ID());
echo $post_data->post_content;

This does not seem to be correct, however. I want to know why the_content () is not working and how to fix it?

plugins – the_content () printing DOCTYPE and tags in the middle of the page

I'm building a custom WordPress theme and I just encountered a strange problem in which the_content () seems to print the page content in the following:


This is a problem because I now have second instances of DOCTYPE tags, html and body appearing in the code of my page. I have attached screenshots below showing the code and the output.

I would appreciate any help as to why this may happen and how I can solve the problem. I've disabled all the plugins, so that does not seem to be the problem.


enter the description of the image here

plugin development – the_content () does not display the description correctly

I'm trying to display the description of a single product WooCommerce, but instead of displaying the correct description, the loop starts again by displaying the image, the price, the price of the product. add to cart, etc.

I've been trying to find the answer for a long time without success.
I've used the WooCommerce template scripts and modified them; the_excerpt () will work but not the_content ().

That's the template file I'm currently using:

the_content () is now the problem. Could this be my request or something? I have a different way of querying my products from index.php, but the archive-product.php file has the same thing as the WooCommerce query. Could this be the cause, even if it is in the single-product.php the problem?

I'm using this for the front-page.php product loop: s:

content-single-product.php, archive-product.php and single-product.php are identical to those of the WooCommerce model.

It should display the description instead of looping back. There is no error message.

how do i add "remove_filter (& # 39; the_content & # 39; wpautop & # 39;);" to the child theme functions in WordPress?

I need to remove the "wpautop tag" from my WordPress website because it adds too many paragraphs. I am new to WordPress. I do not know how to edit children's themes.

plugins – WordPress filter the_content and GET parameter

I have the following problem and I have no idea anymore. I try to explain:
We have some product tests that you need to register. A publication can be a product test, which is indicated by a check box in the edit screen. So, if the checkbox is checked, a form will be attached to the publication via the_content filter. Works well until then. After registration, a participation e-mail is sent to the user to activate himself. And here's the problem: for the activation URL, I attach the user's email, a generated key, and an action variable. I just generated the string and put it in the email. The logic of activation is in the filter_content either. It looks like this:

public service post_show_form ($ content) {
if (! is_single ()) returns $ content;

$ file = & # 39 ;;
if (! ($ val = get_post_meta (get_the_id (), & # 39; is_producttest & # 39 ;, TRUE))) returns $ content;

if (isset ($ _GET[ 'optin_produkttest' ] ) &&! empty ($ _GET[ 'optin_produkttest' ])) {

if ($ this-> model-> already_registered ($ _GET[ 'email' ] )) {

if ($ this-> model-> activate ($ _GET[ 'email' ], $ _GET[ 'regkey' ] )) {
if (function_exists (& # 39; activate_user_in_cr & # 39;)) {
activate_user_in_cr ($ _GET[ 'email' ] )

come back again


& # 39 ;. $ content; } } other { returns $ content. & # 39;


& # 39 ;; } } other { $ start_date = new DateTime (get_field (& # 39; form_test_startdate & # 39 ;, FALSE, FALSE)); $ end_date = new DateTime (get_field (& # 39; form_test_enddate & # 39 ;, FALSE, FALSE)); $ now_date = new DateTime (date ("Ymd")); if ($ now_date <$ start_date) { $ file = & # 39 ;; }other{ if ($ now_date < $end_date ){ $file = 'running'; } else{ $file = 'expired'; } } return $content . $this->view-> get_template ($ file); } }

The problem: the user is always activated immediately and the "isset ($ _GET[ ‘optin_produkttest’ ] ) &&! empty ($ _GET[ ‘optin_produkttest’ ]) "is always defined and they have the right values ​​but I have not defined them, NEVER, how are they defined anyway, how can I, I do not understand it at all.

I hope you understand what I mean, if not ask please. I have to fix that.

Thank you

theme development – the_content () becomes null in Preview Debug

I am not able to edit Page (post-type: page) by Elementor, the Preview theme could not be loaded.

I just created a very simple theme to test, like this:


It is able to display content when it is edited by the classic editor, but it is not able to edit by Elementorand in the Debug Preview view does not display the content inserted by the classic editor.

And it's a new WordPress installation, Elementor is the only plugin enabled

What's missing here?

security – why escape if the_content is not?

Integrated function the contents crosses several filters, but does not escape the output. It would be difficult to do because HTML and even some scripts must be allowed.

At the time of the release, the_content seems to be going through these filters (from version 5.0):

add_filter (& # 39; the_content, & # 39; do_blocks & # 39 ;, 9);
add_filter (& # 39; the_content & # 39;; & # 39; wptexturize & # 39;);
add_filter (& # 39; the_content & # 39 ;, & quot; convert_smilies & # 39 ;, 20);
add_filter (& # 39; the_content & # 39;; & # 39; wpautop & # 39;);
add_filter (& # 39; the_content & # 39 ;, shortcode_unautop & # 39;);
add_filter (& # 39; the_content & # 39 ;, & quot; prepend_attachment & # 39;);
add_filter (& # 39; the_content & # 39;; & # 39; wp_make_content_images_responsive & # 39;);


add_filter (& # 39; the_content & # 39; capital_P_dangit & # 39;);
add_filter (& # 39; the_content & # 39 ;, & # 39; do_shortcode & # 39;);

It is also a simple chain that replaces:

$ content = str_replace (& # 39;

]> & # 39;,

]& gt; & # 39 ;, $ content);

And then get_the_content performs a little treatment related to the link "plus" and a bug with foreign languages.

None of these prevent the injection of XSS script, is not it?

When backing up, the data is sanitized by wp_kses_post. But since this is an expensive process, I understand why it is not used in the output.

The basic rule for escaping WordPress is that everything must be escaped, regardless of disinfection input and as late as possible. I have read several articles on this subject because the database should not be considered as a reliable source.

But for the reasons above, the content does not follow that. Central themes (for example, twenty-nine years old) do not add an extra breakaway.

So … why does it help something to escape elsewhere? If I were a hacker with access to the database, could not I just add my code to the content of a message?