I took as a basis the function of the theme Astra:
/**
* Function to get Read More Link of Post
*
* @since 1.0.0
* @return html
*/
if ( ! function_exists( 'astra_post_link' ) ) {
/**
* Function to get Read More Link of Post
*
* @param string $output_filter Filter string.
* @return html Markup.
*/
function astra_post_link( $output_filter = '' ) {
$enabled = apply_filters( 'astra_post_link_enabled', '__return_true' );
if ( ( is_admin() && ! wp_doing_ajax() ) || ! $enabled ) {
return $output_filter;
}
$read_more_text = apply_filters( 'astra_post_read_more', __( 'Read More »', 'astra' ) );
$read_more_classes = apply_filters( 'astra_post_read_more_class', array() );
$post_link = sprintf(
esc_html( '%s' ),
'<a class="' . esc_attr( implode( ' ', $read_more_classes ) ) . '" href="' . esc_url( get_permalink() ) . '"> ' . the_title( '<span class="screen-reader-text">', '</span>', false ) . ' ' . $read_more_text . '</a>'
);
$output = ' …<p class="read-more"> ' . $post_link . '</p>';
return apply_filters( 'astra_post_link', $output, $output_filter );
}
}
add_filter( 'excerpt_more', 'astra_post_link', 1 );
And wrote my code:
function my_excerpt_more( $more ) {
$read_more_text = apply_filters( 'astra_post_read_more', __( 'Read More »', 'astra' ) );
return ' <a class="my-read-more" href="'. get_permalink( get_the_ID() ) . '">' . $read_more_text . '</a>';
}
add_filter( 'excerpt_more', 'my_excerpt_more' );
But now <p class = “read-more”> is missing. Help, please write the function correctly.
I just wanted to know why the link does not have a class … I do not need to add it, but maybe it will be useful to someone. Thanks!
For example, like this:
function my_excerpt_more( $more ) {
$read_more_text = apply_filters( 'astra_post_read_more', __( 'Read More »', 'astra' ) );
return ' <p class="read-more"><a class="my-read-more" href="'. get_permalink( get_the_ID() ) . '">' . $read_more_text . '</a></p>';
}
add_filter( 'excerpt_more', 'my_excerpt_more' );
But I don’t know if it will be right