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

  • Kadence AI Review: Unveiling the Power of This SEO-Friendly Tool

    Kadence AI is a revolutionary feature that has transformed the process of creating and customizing websites using the Kadence Theme for WordPress. The AI-powered web creation process offers several innovative features that streamline website development and design. One of the standout features of Kadence AI is its “AI-Powered Inline Content,” which empowers users to improve…

  • How to fix the ERR_TOO_MANY_REDIRECTS on Plesk

    Are you seeing this error (ERR_TOO_MANY_REDIRECTS) when trying to access your website URL? We just resolved the same issue on a client’s website. His website is hosted on a Plesk panel. There are a few ways to go around this problem. I will not bother you with the general solutions such as clearing your browser’s…

  • 6 Best WordPress security plugins

    WordPress is gaining popularity day by day as it is currently used by millions of websites around the world. While this free software offers a lot of functionality, it is easily susceptible to security threats. According to an iThemes report, cyberattacks have surged by 300% this year as hackers work harder to take advantage of…

  • Geolocation vs Geofencing: Complete Guide to Location-Based Technologies

    Geolocation vs Geofencing: The Complete Guide to Location-Based Technologies Understanding the fundamental differences, applications, and choosing the right solution for your business in Table of Contents 1. Introduction to Location Technologies 2. What is Geolocation? 3. What is Geofencing? 4. Key Differences Analysis 5. Market Statistics and Trends 6. Technology Comparison 7. Business Applications 8….

  • UptimeRobot Review: Complete Guide to Website Monitoring

    UptimeRobot Review : The Complete Guide to Website Monitoring Discover whether UptimeRobot is the right monitoring solution for your website with our comprehensive analysis of features, pricing, and real user experiences. JoshWP Team | Updated on January Table of Contents 1. Introduction to UptimeRobot 2. Key Features and Capabilities 3. Pricing Plans Analysis 4. Performance…

  • Geo Targetly Review: The Ultimate Geolocation Solution

    Geo Targetly Review: The Ultimate Geolocation Solution for Discover how Geo Targetly can transform your website’s performance by delivering personalized experiences based on visitor location. Try Geo Targetly Free for 14 Days Show Table of Contents Introduction to Geo Targetly Key Features & Functionality How Geo Targetly Works Benefits for Businesses Pricing Plans Comparison User…

Leave a Reply

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