WordPress if is_page function not working

I’m trying to add a function to my WordPress theme that will add content before and after each post, but not on any pages. This does not seem to work, but not sure why.

if(!is_page()) {
  function custom_content($content) {
    $content = 'before post content' . $content . 'after post content';
    return $content;
  }
  add_filter('the_content','custom_content');
}

EDIT: Solution I ended up with that does the trick for me, using is_single to only include on single posts. If you want to include on single pages use is_singular

function custom_content($content) {
    if (is_single()) {
        $content = 'before post content' . $content . 'after post content';
 }
    return $content;
}
add_filter ('the_content', 'custom_content', 0);

Related posts

Leave a Reply

1 comment