Support » Fixing WordPress » Need help with Filter hook

  • Hello, I’m just starting to play with filter hooks and in this instance trying to insert some elements after the post text. The problem that I faced is that all text will render after the post content, but the two functions (get_template_part and similar_posts) that I’m calling would actually render before the post content. This is the code that I’m using in functions.php (you can see how it looks at

    function insertFootNote($content) {
            if(!is_feed() && !is_home()) {
    				//Starting FaceBook button code
    				get_template_part( 'template-part-FaceBook-button-bottom' );
    				//Starting related articles list
    				$content.= "<div id='similar-articles'>";
    				$content.= "<strong>Related Posts:</strong>";
    				$content.= "<br /><br />";
    				$content.= "</div>";
    				//Starting copyright text
                    $content.= "<div id='terms-of-use'>";
                    $content.= "<a href='' title='Terms of use'>© copyright text »</a>";
                    $content.= "</div>";
            return $content;
    add_filter ('the_content', 'insertFootNote');

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Since both get_template_part() and similar_posts() both seem to echo their results to the screen, you probably need use output buffering to capture the output and append the results of those functions to $content:

    get_template_part( 'template-part-FaceBook-button-bottom' );
    $part = ob_get_clean();
    $content .= $part;

    Thank You, vtxyzzy !!! That worked!

    At my current knowledge level I would never get to this 🙂

    Thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Need help with Filter hook’ is closed to new replies.