Add readmore button to excerpt custom HTML
I am trying to display the readmore link in a specific part of my excerpt. The posts are created in a custom plugin, and I write custom HTML as the post_excerpt
. However I want to display a readmore button in the excerpt, without having it at the very end outside all the containers I've made, as I need it to be at a specific location in the HTML DOM to be able to style it.
This is the solution I tried which didn't work for me:
HTML:
This is dummy HTML, not the actual HTML. However it should still give the idea of what I'm doing
div class='container'
a href='#'Button 1/a
!--more--
/div
PHP:
This is added to my functions.php
file
function modify_read_more_link() {
return 'a class=more-link href=' . get_permalink() . 'Your Read More Link Text/a';
}
add_filter( 'the_content_more_link', 'modify_read_more_link' );
The only other solution I think could work is creating the post, collecting the ID from the response from wp_insert_post
, add the post excerpt with the readmore url using the ID, then saving the post with the ID. This does however seem very slow