0

I've got a function in my functions.php that compiles author info for an author box. At the end of the function it return $content;

I then have it being added to the end of the content like this

// Add our function to the post content filter 
add_action( 'the_content', 'author_info_box' );

// Allow HTML
remove_filter('pre_user_description', 'wp_filter_kses');

The problem is that instead of having it print out after the content, I need it to print out directly above the comments. I've got some other code that I'm putting into a page template that I want to show up above the author box. And by attaching the author box to the content I can't insert the other code into the template. Edit: The full function code:

function author_info_box( $content ) {

global $post;

// Detect if it is a single post with a post author
if ( is_single() && isset( $post->post_author ) ) {

// Get author's display name 
$display_name = get_the_author_meta( 'display_name', $post->post_author );


// Get author's website URL 
$user_website = get_the_author_meta('url', $post->post_author);

// Pass all this info to post content  
$content = $content . '<footer class="author_bio_section" >' . $author_details . '</footer>';
}
return $content;
}

// Add our function to the post content filter 
add_action( 'comment_post', 'author_info_box' );

// Allow HTML in author bio section 
remove_filter('pre_user_description', 'wp_filter_kses');
1

You could change the function to echo like this:

echo apply_filters('the_content', $content);

and then in your template, right before the comments template, place the call to your author box function like this:

author_info_box();

also, you would need to remove the add_action('the_content', 'author_info_box');

Full function example:

function author_info_box() {

    global $post;

    // Detect if it is a single post with a post author
    if ( isset( $post->post_author ) ) {

    // Get author's display name 
    $display_name = get_the_author_meta( 'display_name', $post->post_author );


    // Get author's website URL 
    $user_website = get_the_author_meta('url', $post->post_author);

    // Pass all this info to post content  
    $content = '<footer class="author_bio_section" >' . $author_details . '</footer>';

    echo apply_filters('the_content', $content);
    }
}

Note: apply_filters iterates through all the functions that are registered to whatever filter is set (in this case, the_content). Once the last function is done it will return the "filtered" content and thus needing the echo to print it out.

  • Does it need to be echo apply_filters or just apply_filters? And where is the $author_output coming from? – jonbon Oct 13 '16 at 0:32
  • I edited the original post to show you the full function I'm using. – jonbon Oct 13 '16 at 0:35
  • It needs to have the echo and instead of $author_output use the $content, i've updated my answer with an explanation of apply_filters – stims Oct 13 '16 at 0:54
  • Okay, because that's what I tried and its not showing up. Let me look at it again. – jonbon Oct 13 '16 at 0:55
  • 1
    If you are still have trouble, I'd like to see where you put the author_info_box(); function. – stims Oct 13 '16 at 1:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.