• Resolved Morgan Grip

    (@morganmmg)


    I want to hide specific pages from appearing in the Post navigation (the forward and backward-links in post footer) but can’t figure out how to do that?

    • This topic was modified 4 years, 6 months ago by Morgan Grip.
Viewing 5 replies - 1 through 5 (of 5 total)
  • You would first need to determine the source of the code.
    It would most likely be your theme.
    Once you have isolated the code, it becomes possible for volunteers to give you some options on how / where to edit it.

    Ok, i dont know if that would help. I just want to hide certain specific pages, but here is the code:

    `<div class=”fl-row fl-row-full-width fl-row-bg-none fl-node-5e78b92b94134″ data-node=”5e78b92b94134″>
    <div class=”fl-row-content-wrap”>
    <div class=”uabb-row-separator uabb-top-row-separator”>
    </div>
    <div class=”fl-row-content fl-row-full-width fl-node-content”>

    <div class=”fl-col-group fl-node-5e78b92b9c19a” data-node=”5e78b92b9c19a”>
    <div class=”fl-col fl-node-5e78b92b9c34c” data-node=”5e78b92b9c34c”>
    <div class=”fl-col-content fl-node-content”>
    <div class=”fl-module fl-module-fl-post-navigation fl-node-5e78b12b7f899″ data-node=”5e78b12b7f899″>
    <div class=”fl-module-content fl-node-content”>

    <nav class=”navigation post-navigation” role=”navigation” aria-label=”Inl?gg”>
    <h2 class=”screen-reader-text”>Inl?ggsnavigering</h2>
    <div class=”nav-links”><div class=”nav-previous”>← Page Title</div><div class=”nav-next”>Page Title →</div></div>
    </nav> </div>
    </div>
    </div>
    </div>
    </div>
    </div>
    </div>
    </div>

    A possible code solution for this may be the following:

    /**
     * Remove certain posts from appearing in adjancency
     * 
     * @param String $html			- Final Output HTML
     * @param String $format		- Link anchor format
     * @param String $link			- Link URL format
     * @param WP_Post $given_post	- The given WP Post
     * @param String $adjancency	- next/previous
     */
    function wpf12784795_remove_adjacent_post( $html, $format, $link, $given_post, $adjancency ) {
    	
    	global $post;
    	
    	/**
    	 * Preferably these should be IDs since they don't change
    	 * But they could be any Post property such as Slug or Title
    	 */
    	$forbidden_posts = array(
    		123,
    	);
    	
    	// Check if the given post ID is in our forbidden Array
    	if( ! empty( $given_post ) && in_array( $given_post->ID, $forbidden_posts ) ) {
    		
    		// Temporarily overwrite the global $post object
    		$post = $given_post;
    		
    		$html = get_adjacent_post_link(
    			$format,
    			$link,
    			$in_same_term	= false,		// Whether it matters to grab an adjancent post from the same category/term
    			$exclude_terms	= '',			// Exclude any specific terms by ID
    			$previous		= ( 'previous' === $adjancency ),	// Whether it's a previous or next adjancency
    			$taxonomy		= 'category'	// Custom taxonomy if not dealing with the built-in category
    		);
    		
    		// Reset the global $post object
    		wp_reset_postdata();
    		
    	}
    	
    	// Always return the HTML
    	return $html;
    	
    }
    add_filter( 'previous_post_link',	'wpf12784795_remove_adjacent_post', 10, 5 );
    add_filter( 'next_post_link',		'wpf12784795_remove_adjacent_post', 10, 5 );

    The above does not work on all prev/next post links so it depends which specific function you’re using. I don’t know of a plugin that will help you in this regard though so if the above does not work for you then you’ll need to dig deeper to figure out what function(s) is generating the links.

    The code that you included is the HTLM that is output on the page.
    As Howdy_McGee indicated, you need to adjust the PHP (which happens on the back end).

    Hopefully his code snippet will work as-is for you.

    As an alternative, why don’t you just redirect those pages for users that are not logged in?

    @howdy_mcgee Works perfectly as i wanted. Thanks! Hats Off to you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Hide pages from Post Navigation’ is closed to new replies.