[Support request] Inside entry-content

Home Forums Support [Support request] Inside entry-content

Home Forums Support Inside entry-content

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #388623
    Anthony

    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 ?

    #388825
    Leo
    Staff
    Customer Support
    #388948
    Anthony

    This hook add content after the .entry-content element, while i need to output content inside it, at the very end

    #389066
    Leo
    Staff
    Customer Support
    #1303176
    Rafał

    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?

    #1303251
    David
    Staff
    Customer Support

    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

    #1303302
    Rafał

    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');
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.