S
S
Shigaev.2020-06-12 11:00:05
WordPress
Shigaev., 2020-06-12 11:00:05

How to wrap an announcement (excerpt) with a link to a post in Wordpress?

The link to a Wordpress post is usually its title. How to make a link also the text of the announcement (excerpt)? I can’t create the appropriate filter in functions.php - I still don’t know much about WP.

In index.php I have this:

<?php 
if ( is_search() ) {								
  the_excerpt();
} 
else {
 the_content(); 
 edit_post_link();
}
?>


While I see an option - wrap it through a filter with a permalink the_excerpt();and, most likely, with a link to is_home (or is_frontpage), so that the entire text of the post does not turn out to be a link. But I don’t know how to implement it, I can’t find options for analogs of solving the problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Sarvarov, 2020-06-12
@Shigaev

Well, yes, either find it in the template the_excerpt();and wrap it with a link, or use a filter:

add_filter( 'the_excerpt', function ($content) {
    return sprintf( '<a href="%s" rel="bookmark">%s</a>', get_permalink(), $content );
} );

and, most likely, with reference to is_home (or is_frontpage), so that the entire text of the post does not turn out to be a link either

I didn’t quite understand why the main text should be affected the_content().

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question