The difference between the_content() and get_the_content()

If you’re a WordPress developer, you probably know WordPress function the_content()can be directly output the contents of the article, but get_the_content()you need to add in front of echoit can output the contents of the article.

<?php
the_content();

echo get_the_content();
?>

This is a very important sign of WordPress built-in functions. The first the_function is directly output, and get_ the first function does not execute output.

However, the difference between the two is not only that:

  1. get_the_content()Will not the_contentpass content. This means it will not automatically embed videos or expand shortcodes. So, use it get_the_content()and it will delete tags such as embedding and shortcode.
  2. get_the_content()The acquired content is the original saved data, without paragraph tags p, so that the content that should be segmented cannot be segmented. That <?php echo get_the_content(); ?>and <?php the_content(); ?>the content of the output is not the same, the former will filter out a lot of labels. So, if you want to output the complete content of the body, please use<?php the_content(); ?>

Recently toss the project encountered this problem, this thoroughly understand <?php echo get_the_content(); ?> and <?php the_content(); ?>is really not the same.

Leave a Reply

Your email address will not be published. Required fields are marked *