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

Leave a Reply

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