I'm converting my posts over to use the new Block Editor. In the past I added an icon to the end of every post to act as a signature and marker saying the article is over (like print magazines do).
I did it like this:
// Add Signature Image at End of Posts
add_filter('the_content','td_add_signature', 1);
function td_add_signature($text) {
global $post;
if(($post->post_type == 'post'))
$text .= '<span class="icon"></span>';
return $text;
}
That would insert the 'span class=icon' right after the final period, before the closing paragraph tag.
Now, with the new Block Editor, it adds it after the final closing paragraph tag.
So my question is, does anyone know a way to locate the final paragraph of the_content and then inject this HTML inside the 'block?' I'm assuming I might have to locate the last paragraph somehow, explode it or just string_replace the last closing p tag with the "HTML + p tag."
I'm simply not that good at PHP and am not sure how to "locate" the last paragraph in the_content.
I realize this can be done with jQuery easily but I'd much rather do it with a functions.php function and have it correct in the markup server-side. I could also create a custom "Last Paragraph" block that adds it for me, which is kind of goofy.
Thanks for any help or insight. It's my first question and post!