Not sure it’s strictly the answer but I found a plug-in which still meant I needed to edit my functions.php file and was probably overkill for what I wanted but it resolved the issue and I binned the code above completely.
Related Posts:
- previous/next_post_link in the same sub-category?
- adding custom fields to next and previous post link
- WordPress previous_post_link exclude posts with multiple categories
- Can I use get_adjacent_post for specific categories?
- Exclude Posts From Specific Category from Next and Previous post links
- Show category from “Next post” and “Previous post” [edited]
- Previous/next post links displaying wrong category than is desired
- Link to the next/prev posts in index loop in same category?
- Single.php Category Post Count
- Get next post in same category not working WP 4.7.4
- Change next_post and previous_link to navigate throught parent categories only
- how to implement next/prev within category archive?
- Get the children of the parent category
- wp_nav_menu not appearing for a couple pages
- Main menu not appearing on category pages
- How can I limit the length of the previous/next posts in my WordPress Theme?
- Problem excluding category from get_next_post
- specify meta_key / meta_value condition for prev_post_link and next_post_link
- Is it possible to put next and previous category links?
- Post in Multiple Categories to stay in current category (permalink, next previous post link)
- next_post_link and previous_post_link in custom post type single page, in same non-custom category
- Previous/next link to post in category, NOT tag?
- connect last post with first post
- Multiple menu items highlighted
- wp_nav_menu not highlighting the current category when viewing a single post
- Open subcategories in submenu on click in primary menu
- How to display only posts assigned to a particular, isolated, subcategory
- Is it possible to nest get_previous_post()?
- Checkboxes in the category list?
- Get Prevous/Next Post Specific Category Without Excludes
- Restoring default article pagination on archives – Removing custom limits
- posts_nav_link(); picks up index.php instead of category.php as template
- get_adjacent_post – in same term or category not working
- Create menu / submenu from category subcategory and posts
- How to get Next/previous_post_link to go through articles in top parent category
- How to display numbered pages in a category
- next_post_link / previous_post_link not working with WP_Query
- Ambrosite Next/Previous Post Link Plus or WP next_post_link to cycle through top level category
- Give Children Unique ID’s
- Multiple categories for one menu item?
- Show next post in same category but start from the latest
- Can’t get the previous and next posts permalink
- Next/Previous links doesn’t work in the same category
- How do I display a greyed out next_post_link when there is no next post
- Global navigation in multisite: problem with categories
- Include “Scheduled” (“Future”) Posts in WordPress Post Navigation ( previous_post_link, next_post_link ) for a Specific Custom Post Type
- How to get next post link of child custom post type from parent post and get next post link of parent post from the last child post?
- display specific category when website loads
- How to exclude posts by meta key value in the_post_navigation next prev links?
- Prev/Next Navigation on Single Post Disappeared for Custom Post Type
- How to add all subcategories as submenu in WordPress menu
- Change URL of previous posts and next posts link in WordPress
- Dynamic next and previous post links
- Next and previous links category infinite loop
- omit categories from main navigation menu
- Loop within category’s posts
- Next/Prev category post in same button
- Grouping parent categories into sections
- A simple question regarding tags and categories
- get_adjacent_post_link excluded_terms ignored
- Transfering static site to wordpress and retaining category by month paginations
- Get all first images of posts in same category
- In category.php I need to get the next 10/previous 10 posts
- Previous / next posts using featured image thumbnail as links
- Is there a function to modify existing previous/next post link without modifying theme files?
- How can I get category ID by category name?
- Randomise results from a category page?
- Adding Custom User Profile data based upon Categories
- Order posts by category name
- How can I make wp_list_categories output li with category-slug as class, for its children?
- Output link to category from WP_Query loop of woocommerce products
- If in category to be inside of a function
- How to exclude posts from a category when using this particular format
- Show only one category
- Pagination Not Working on Category.php page
- one category template for multiple categories
- How can I define a custom archive for childs of a specific category?
- REST API: Display Category names in JSON?
- List posts in alphabetical order
- Categories list loop – add separator every 3 categories [closed]
- how to separate categories in loop.php?
- How can i remove the posts category class names from body_class
- Different Category Headers using in_category and elseif
- Show category meta in loop on homepage
- Category link redirect to custom template page instead of index.php?
- Add class to current post in query_post
- Sort posts by child category name
- How to define a post category undeletable by other users?
- Displaying portions of multiple pages from a given category, in a single summary page
- Change wp_link_pages to link to another page
- Post url rewriting for posts with certain category
- Hide post category name wherever it might be mentioned
- get_the_terms_list output last child only
- How to loop through a custom field for each post, & display?
- Lowest catagory link
- Displaying posts from a Category where the Category ID or slug is not known
- Custom CSS to resize elements in multiple categories
- Way to show content of a post, but if exceeds character limit revert to excerpt?
- Why does my WordPress index has a category?
- how do I exclude a category foreach