Home > Software design >  WordPress where find code function the_excerpt()?
WordPress where find code function the_excerpt()?

Time:10-21

This is my code:

            <div >
                <?php the_excerpt(); ?>
            </div>

But I would like to edit what the_excerpt function displays. Is it possible to reach the_excerpt function code? Where to find that function in WordPress files?

Thanks!

CodePudding user response:

You can modify the output of the_excerpt() by hooking to it in functions.php:

Add the following code to your functions.php:

function my_custom_excerpt($excerpt) {
    $excerpt = 'some prefix text ' . $excerpt . ' ...and some more';
    return $excerpt;
}
add_filter('get_the_excerpt', 'my_custom_excerpt', 999 );

WordPress is open source, so you can view the source code for any function (including the_excerpt()) on the WP Developer Resources website: https://developer.wordpress.org/reference/functions/the_excerpt/

Also, here is a guide for changing different parts of the excerpt: https://wpshout.com/wordpress-post-excerpts/

CodePudding user response:

I'm not sure what you mean by "reach the_excerpt function code". If you want to change the output of the_excerpt() you can use the_excerpt filter. If you want to change the code of the_excerpt() you can find it in wp-includes/post-template.php.

CodePudding user response:

This is my problem, function the_excerpt() take button name „UDOSTĘPNIJ:” and push it into post content. I want to change function the_except() that it only take paragraph, not all strings.

https://i.stack.imgur.com/aEunW.jpg

  • Related