• Hi,

    First, I would like to thank you for this very useful plugin.

    On few pages, I would like to choose to display no related post at all. However if I let the field blank, it fills the related posts by guessing itself.

    Thanks for your help

    N.

Viewing 1 replies (of 1 total)
  • Hi @dagnic75,
    Thanks for your post.

    I can see there isn’t a built-in option to exclude a page. But we have a filter hook available. I’ve already written the code for you, and Please copy the code below and from your WP dashboard, go to Appearance => Theme File Editor.
    Select the Theme Functions file from the right side and paste the code at the very end of the file. (kindly follow my screenshot)
    Screenshot: https://i.imgur.com/sdLi73j.png

    Code to Copy:

    add_filter('related_post_query_args','related_post_query_args_20200126');
    function related_post_query_args_20200126($args) {
    	
    	$postOrPageIDsToExclude = ['141', '142',]; // add post/page ID's you want to exclude
    	
        if(in_array(get_the_id(), $postOrPageIDsToExclude)){
    		return '';
    	} else{
    		return $args;
    	}
    }

    Note: On the code, you can see a variable called $postOrPageIDsToExclude. Just add the page ID that you want to exclude. And update the file.

    Wondering where to find the page ID?
    First, go to the Edit interface for your post/page.
    Screenshot: https://i.imgur.com/wD9KsYZ.png

    And you can find the ID in the URL section.
    Screenshot: https://i.imgur.com/OzYqdnh.png

    Let me know if it helps.
    Regards.

Viewing 1 replies (of 1 total)
  • The topic ‘Choose to display no related page’ is closed to new replies.