Support » Fixing WordPress » Excluding specific post from custom next/previous theme function

  • My Genesis child theme comes with its own plugin to customize the design. They recently added a Next/Prev post thumbnails bock at the bottom of the content area.

    The only problem is that some of my posts have dynamic content boxes that are embedded via javascript that stretch the page and cause overlap issues with the related posts, so I’d like to exclude those dynamic pages from using this function.

    Here’s a screenshot: https://imgur.com/a4X7b1s

    Within the theme’s accompanying plugin, they seem to use this to add it to the backend admin settings and output the code:

    add_action( 'after_setup_theme', __NAMESPACE__ . '\\set_modern_prev_next', 101 );
    /**
     * Modern Prev + Next 
     */
    function set_modern_prev_next() {
        if ( '1' === Settings::get( 'modern_prev_next' ) ) {
            remove_action( 'genesis_after_entry_content', 'genesis_prev_next_post_nav', 5 ); // for Foodie, Cook'd.
            add_action( 'genesis_after_entry_content', __NAMESPACE__ . '\\modern_prev_next', 5 );
        }
    }
    function modern_prev_next() {
        
        if ( ! is_singular( 'post' ) ) { return; }

    I’ve been going through the WordPress documentation, and found the use of filters could solve this. I’ve added this snippet:

    add_action('template_redirect', 'excl_modern_prev_next', 10 );
    function excl_modern_prev_next() {
        if ( is_singular('11717') ) {
            remove_action( 'genesis_after_entry_content', 'modern_prev_next', 5 );
        }
    }

    But it doesn’t seem to work, I’m not sure if it’s the hook, priority or something else that I’m overlooking?

    Thank you

Viewing 1 replies (of 1 total)
  • Thread Starter Soprano

    (@soprano)

    Thanks for the response.

    The Next/Prev title and thumbnails are pulled from the category in which the post is located. It’s just a regular wordpress post type, no custom post types are used.

    So the user is just visiting the normal post, and when they click one of the next/prev post images that are pulled from the same category, it takes the user to that post.

    You can see a live demo at the bottom of the themes sample site blog post which is showing next/prev posts in the Breakfast category: https://foodiepro.com/block-editor-styling/

Viewing 1 replies (of 1 total)
  • The topic ‘Excluding specific post from custom next/previous theme function’ is closed to new replies.