Archived topic
Inside entry-content
6 replies · Started by Anthony on September 20, 2017
Hey,
Is there a Generatepress hook to place additional content inside the class="entry-content" element, but as the very last element ? or is it a wordpress hook ?
Hi there,
This one maybe? https://docs.generatepress.com/article/generate_after_entry_content/
This hook add content after the .entry-content element, while i need to output content inside it, at the very end
What about after content? http://demo.generatepress.com/hook-locations/
We can do it with add_filter function in functions.php
function append_to_the_entry_content($content) {
if (is_singular()) {
$content .= '<p class="appendix">My Appendix</p>';
}
return $content;
}
add_filter('the_content', 'append_to_the_entry_content');
Of course, using needed condition instead of is_singular().
If the appendix is complex it'd be convenient to fetch the content of a post or a page (which may stay unpublished).
$content .= get_post(1234)->post_content;
How you think, can we append HTML to the entry content in a smarter way?
Hi there,
thanks for sharing, yes the Filter method is the correct way of appending content. And there isn't another way to the best of my knowledge
When source HTML has been created in block editor (Gutenberg) then with do_blocks() function I can get rid of block comments eg. <!-- wp:paragraph {"className":"appendix"} -->.
function append_blocks_to_the_entry_content($content) {
if (is_singular()) {
$content .= do_blocks(get_post(1234)->post_content);
}
return $content;
}
add_filter('the_content','append_blocks_to_the_entry_content');