Support » Themes and Templates » How to add something after the post?

  • I am trying to display terms of my custom taxonomy below the posts. I can add

    <?php the_terms( $post->ID, 'people', 'People: ', ', ', ' ' ); ?>

    But I want to add it to my child theme’s functions.php file so that no matter which theme I use the terms get displayed below the post.

    I know about action hooks and I think I can hook this with the_content I tried this code

    function my_terms($content) {
    	$terms .= the_terms( $post->ID, 'people', 'People; ', ', ', ' ' ); ;
    	return $content.$terms;
    add_action('the_content', 'my_terms');

    It works but it adds terms between post content and title. I would like the terms to appear after the content. Can someone please tell me how I can do this?


Viewing 6 replies - 1 through 6 (of 6 total)
  • You should use add_filter instead of add_action.
    Here is an example:

    gidd thanks for the tip but even with add_filter the custom content appears before the post between post content and post title.

    I tested it on twenty twelve and twenty eleven. same result. Here is the code I tried:

    function add_post_content($content) {
    	if(!is_feed() && !is_home()) {
    		$content .= '<p>' . the_terms( $post->ID, 'people', 'People: ', ', ', ' ' ) . '</p>';
    	return $content;
    add_filter('the_content', 'add_post_content');

    I think your problem lies within 'People: ', ', ', ' ' )

    Something like 'People: ', '', '', '') or just 'People: ') would be correct.

    You know, as in ‘something here’, ‘or’, ‘something’, ‘else’ and for now you only have the “opening quote” for all of those.

    jimhenrik thanks for the tip, removed there and used 'People: ') still the same result. I also noticed that the filter strips out HTML <p> and </p>

    It just shows People: Bob, Karen right above the post with no <p> surrounding them.

    I have to apologize first and admit, that I have not worked with any of the filters, ever.

    Still, that’s quite strange. With a quick googling that should be the right code.

    function your_content($content){
      if (is_single()) {
        $content .= '<p>Your Content Here</p>';
      return $content;
    add_filter( "the_content", "your_content" );

    I got replacing the < with &lt and &gt but it still strips them out. Also terms still appear below the title instead of below the post content.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to add something after the post?’ is closed to new replies.