With this WordPress related PHP-OOP Answer, I found my solution for what I's seeking. But with the same function my_excerpt();
I want to pass another anchor tag (<a>
) inside the <p>
tag.
Right now, calling my_excerpt()
is embracing the db texts with a paragraph tag (<p>here comes the excerpt</p>
). And if I add my anchor tag like the following:
// Echoes out the excerpt
public static function output() {
the_excerpt(); ?>
<a class="read-more" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" rel="bookmark"><?php _e( 'Read More »', 'my-theme'); ?></a>
<?php
}
it's showing the "Read More" just the bottom of the except texts. Inspect Element shows like the following:
<p>here comes the excerpt.</p>
<a href="post-link">Read More</a>
How can I make changes to the function or class so that I can have the "Read More" link inside the paragraph, like:
<p>here comes the excerpt.<a href="post-link">Read More</a></p>
Additionally
Additionally I'm also trying to remove the [...]
part from the excerpt generating by the my_excerpt();
. So I tried the following:
function change_excerpt($content) {
$content = str_replace( '[...]','>',$content ); // remove [...], replace with ...
$content = strip_tags( $content ); // remove HTML
return $content;
}
add_filter('my_excerpt','change_excerpt');
I doesn't do anything to the view. But if I change it to:
add_filter('the_excerpt','change_excerpt');
Then unaware, I get the previously desired anchor tag [inside paragraph], because the filter removed the paragraph tag completely.
here comes the excerpt.<a href="post-link">Read More</a>
But it doesn't do anything with [...]
portion. :(
So, my furnished Question is:
How can I put the anchor tag inside the paragraph tag, or remove the paragraph tag, and remove the [...]
part from the my_excerpt()
function?