• Resolved lowestofthekeys

    (@lowestofthekeys)


    I’ve setup my functions page with the following code which adds content to the end of every post:

    function custom_post_content($content) {
    global $post;
    $permalink = get_permalink($post->ID);
    $title = get_the_title();
    if(!is_feed() && !is_home() && !is_page()) {
        $content = $content . 'Yaketty smacketty';
    }
    return $content;
    }
    add_filter('the_content', 'custom_post_content');

    My question is, is there a way to only allow this custom content to appear on posts for specific categories.
    I tried doing this by adding:
    && !in_category('blog')
    to the mix but it does not seem to be working.

Viewing 3 replies - 1 through 3 (of 3 total)
  • What’s the entire if statement? Did you write it like this:

    if(!is_feed() && !is_home() && !is_page() && !in_category('blog')) {
        $content = $content . 'Yaketty smacketty';
    }

    What do you mean by “not working”? Is it displaying posts that it shouldn’t? Or not displaying posts that it should?

    Are the posts assigned directly to the “blog” category, or is “blog” a parent category?

    A URL to your site wouldn’t hurt too.

    Thread Starter lowestofthekeys

    (@lowestofthekeys)

    Yes, I added the “!in_category(‘blog’)” to the function, but it doesn’t work in the sense that the custom content is not filtered to the blog category.

    I’ve tried using the slug ID and removing “!is_page” from the function, but I can not seem to get the custom content to appear under only the blog category posts.

    Thread Starter lowestofthekeys

    (@lowestofthekeys)

    Found the solution…it just need to only include the in_category(‘blog’) portion.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Quick question about adding custom content to the end of every post’ is closed to new replies.