WordPress automatically intercepts part of the content of the article as a summary

In the daily release of articles, not every article may have an article summary, so the summary function of WordPress can not meet our needs.

This article shared by wptootutorial network introduces a WordPress technique of automatically intercepting part of the content of an article as an article summary, and can customize the number of intercepted words to solve this problem perfectly.

code snippet

<?php if (has_excerpt()) {
 echo $description = get_the_excerpt(); //Abstracts in article editing
}else {
 echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 170,"……"); //If the article has no abstract,Choose the number of words in the article as the summary
} ?>

usage method

Copy and paste the above WordPress code into the website using the theme functions.php It’s just in the middle.

Related Article
Implementation of tag inner chain association effect of WordPress program without plug-in

Nowadays, whether it is a large website or a personal blog, what matters is not the weight of the website Read more

Is in WordPress Theme_ Home () and is_ front_ Different usage of page ()

Under normal circumstances, when we use WordPress to build a website, the home page is the default index.php Just call Read more

How to delete the version number tail of WordPress scripts and CSS style sheets

As an excellent website building program, WordPress is undoubtedly the largest user group in the world in terms of user Read more

Solve the problem of “upload error, please try again later” in WordPress image upload

One of the reasons why I like to use WordPress is that I have encountered problems. Basically, I can find Read more

Leave a Reply

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

To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image