How to exclude a post from the Related Posts block

How to disable a specific post from showing in the Kadence Theme Related Posts block

How to exclude a post from the Related Posts block

To disable a specific post from showing in the related posts block at the end of each post in WordPress with the Kadence theme, you can follow these steps:

  1. Identify the Post: First, you need to identify the specific post that you want to exclude from the related content block.
  2. Use Plugins or Extensions: WordPress has plugins that allow you to control the visibility of specific posts in the related content block. You can install and use one of these plugins.
  3. Modify the Theme Settings: In the Kadence theme, you can go to Appearance > Customize > Theme Settings > Blog: Related Posts to control the related content.
  4. Use Code Snippets: If you’re comfortable with coding, you can add a code snippet to your theme’s functions.php file. Please note that this method should be used with caution as it involves modifying the theme’s code.

Remember, always backup your site before making any changes to the theme’s code. If you’re not comfortable with coding, it’s recommended to use a plugin or seek help from a professional.

How to exclude a post from the related posts section using the Code Snippets plugin

You can use the Code Snippets plugin to add a custom function to your WordPress site. Here’s a simple example of how you might exclude a specific post from the related posts section. This code would go into a new snippet in the Code Snippets plugin:

PHP Snippet

function exclude_specific_post_from_related( $args ) {
    // Replace 123 with the ID of the post to exclude
    $post_to_exclude = '123';

    if ( isset( $args['post__not_in'] ) ) {
        $args['post__not_in'][] = $post_to_exclude;
    } else {
        $args['post__not_in'] = array( $post_to_exclude );
    }

    return $args;
}
add_filter( 'kadence_related_posts_args', 'exclude_specific_post_from_related' );

In this code, replace 123 with the ID of the post you want to exclude. This function modifies the query arguments for the related posts, adding the specified post to the ‘post__not_in’ parameter, which excludes it from the query.

To identify the post ID on your site, open the post on your site’s backend and look for the number within the post’s URL on your content editor. E.g., https://yoursite.com/wp-admin/post.php?post=9217&action=edit. In this case, 9217 is the post ID.

Please note that this is a general example and might not work depending on your specific setup. Always back up your site before making changes, and consider consulting with a professional if you’re unsure.

To add the code to your site using code snippets, create a new snippet>add code> change code type to PHP> set location to sitewide footer > save.

How to exclude a post from the Related Posts block

How to exclude multiple posts from the related posts section

How to exclude two posts from the related posts section

If you want to exclude two posts from the related posts section, you can modify the code snippet to include the IDs of both posts. Here’s how you can do it:

PHP Snippet

function exclude_specific_posts_from_related( $args ) {
    // Replace 123 and 456 with the IDs of the posts to exclude
    $posts_to_exclude = array('123', '456');

    if ( isset( $args['post__not_in'] ) ) {
        $args['post__not_in'] = array_merge( $args['post__not_in'], $posts_to_exclude );
    } else {
        $args['post__not_in'] = $posts_to_exclude;
    }

    return $args;
}
add_filter( 'kadence_related_posts_args', 'exclude_specific_posts_from_related' );

In this code, replace 123 and 456 with the IDs of the posts you want to exclude. This function modifies the query arguments for the related posts, adding the specified posts to the ‘post__not_in’ parameter, which excludes them from the query.

How to exclude three posts from the related posts section

If you want to exclude three posts from the related posts section, you can modify the code snippet to include the IDs of all three posts. Here’s how you can do it:

PHP Snippet

function exclude_specific_posts_from_related( $args ) {
    // Replace 123, 456, and 789 with the IDs of the posts to exclude
    $posts_to_exclude = array('123', '456', '789');

    if ( isset( $args['post__not_in'] ) ) {
        $args['post__not_in'] = array_merge( $args['post__not_in'], $posts_to_exclude );
    } else {
        $args['post__not_in'] = $posts_to_exclude;
    }

    return $args;
}
add_filter( 'kadence_related_posts_args', 'exclude_specific_posts_from_related' );

In this code, replace 123, 456, and 789 with the IDs of the posts you want to exclude. This function modifies the query arguments for the related posts, adding the specified posts to the ‘post__not_in’ parameter, which excludes them from the query.

Disclosure: We may earn commission for purchases that are made by visitors on this site at no additional cost on your end. All information is for educational purposes and is not intended for financial advice. Read our affiliate disclosure.

Share this:

Similar Posts

  • How to fix cURL error 7 failed to connect to Port 443

    If you have encountered a “cURL error 7 failed to connect to Port 443” you know how stressful it is to figure out a solution. It causes a website to have a poor security check score altering your site’s performance. I once encountered a “cURL error 7 failed to connect to Port 443” on one…

  • Fastest WordPress themes: Best free lightweight themes

    The fastest WordPress themes in the market today include the following: Are you looking for the best free lightweight WordPress themes? Look no further! We have compiled a list of the top options available. Performance test of the fastest WordPress themes I created a simple WordPress website using each theme on a Vultr basic cloud…

  • IP Geolocation Databases: The Complete Guide

    IP Geolocation Databases: The Complete Guide for Understanding the technology that powers location-based intelligence in the digital world IP geolocation databases have become an essential technology for businesses seeking to harness location-based intelligence in today’s digital landscape. These powerful tools map IP addresses to physical locations, providing valuable insights that drive personalization, security, and business…

  • 9 Best WordPress caching plugins for improving site speed

    Are you looking for the best WordPress caching plugins? Caching is an essential aspect of website performance, as it helps to reduce the load on the server and speed up the delivery of content to users. If you’re using WordPress to power your website, you have a range of caching plugins to choose from that…

  • WriteHuman Review: How to Humanizer AI articles using WriteHuman

    Would you like to have a more human touch in your AI-generated texts? Don’t worry. In this WriteHuman review, I will delve into a cutting-edge tool that bridges the gap between artificial intelligence and real human communication. WriteHuman is your secret weapon for creating content that resonates, whether you are a student, a blogger, or…

Leave a Reply

Your email address will not be published. Required fields are marked *