The code you posted does nothing but display. The code you need to alter is whatever is creating $prevID and $nextID, but that might not be entirely relevant.
Basically, you just need to grab a random post.
$rl = new WP_Query(
array(
'posts_per_page' => 1,
'orderby' => 'rand',
'fields' => 'ids'
)
); ?>
<div class="alignleft">
<a href="https://wordpress.stackexchange.com/questions/129453/<?php echo get_permalink($rl->posts[0]); ?>" title="<?php echo get_the_title($rl->posts[0]); ?>">Random</a>
</div><?php
I don’t see the point of two random post links but the same technique will work.
Also, using random links in your navigation isn’t really navigation. It doesn’t help your users navigate. It just randomly tosses them around the site.
Related Posts:
- Function to return true if current page has child pages
- Cleaning up WordPress to improve performance?
- List of all theme customizer control types?
- Show the most popular post per week
- Add a class to links in the visual editor (how to get old dialog back)
- Creating custom Woocommerce attribute taxonomies from a plugin
- Remove/unset options field from backend Settings->General?
- Display posts by month
- How to preserve PHP modifications while upgrading WordPress?
- Removing jQuery migrate and working with dependencies
- Load post content into iframe
- is there a simple way to list every templates / php files used to generate a specific page?
- wp_customize_image_control default value
- How To Customize Position of »add to cart« of WooCommerce on Product Page [closed]
- Authenticating to WordPress, using my own authentication two-factor system
- Overriding a theme redux file in child theme
- there’s a way to include a minimal WP for check only the current user, its roles (caps?) and then release/free it?
- Widgets not showing in my custom theme
- Second Navigation inside header
- How to display custom field on homepage
- How to display something in a div when the user clicks on a text in another div – no page refresh [closed]
- How to get 2 or multiple custom post types in wordpress functions.php
- Creating bulk posts with Youtube videos
- Trouble creating conditional PHP for nav menu items with children for custom Walker
- Setting custom canonical urls
- Only show search results with if current date is between two dates?
- database interactions using OOP
- Hide Hamburger Menu On Specific Page (Front Page/Home Page)
- WordPress blog post url on category page
- Extending the WP_Widget_Text class
- Menu Limitations
- Retrieve $_POST data submitted from external URL in WordPress(NOT API)
- Trying to build simple deposit code that hooks into woocommerce
- Custom Walker_Nav_Menu issue with variables on PHP 7.3
- user_profile_update_errors hook not executing
- Saving and Restoring a Canvas on A Individual User Basis
- Extend plugin Class through functions.php
- How to add a do_action on refreshing of WP customizer?
- Weird 404 URL Problem – domain name being placed at end of urls
- Output custom field value to post string
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- how to show only specific category for a template
- How to get private property in parent class into extended class?
- “operation successful” message
- Clickable image link sends people to wrong URL
- Create page template via functions.php?
- How to include custom PHP file both in header and footer files
- Delete or edit postmeta with specific meta_key?
- How to Handle Going Backwards in Navigation When Referrer in PHP/JavaScript won’t work?
- get_theme_mod outputs number when using WP_Customize_Cropped_Image_Control
- Update if post with specific title exists
- Reusable code that I can store in the function.php and apply to other templates as need. Dry Code
- posts_nav_link pulling in multiple post types
- Assign Custom classes to every Excerpt
- Why can’t I add a custom image in my navigation?
- pass html code to worpdress
- How do I custom code the start page?
- Kohana Frontend, WordPress Backend
- is_user_logged_in returning nothing on custom page
- Customize field names in backend profile edit page through function.php [duplicate]
- Remove the Tag from wp_nav_menu
- how to add datas in taxonomy to post with wp_insert_post
- WordPress navigation wont appear with wp_head
- Change permalink structure specific category
- WP_REST_Response – How to return Gzip answer and add Content-encoding header?
- Create Columns with Custom Walker and CSS Classes
- I need to display posts in subcategory beside posts in main category
- How can I check that the acf field value is not a duplicate when adding a post?
- Adding an Anchor Link to a wordpress menu using WPBakery Page Builder
- Removing “There is no account with that username or email address.” error message in “/wp-login.php?action=lostpassword”
- Inserting a class on before_widget if checkbox is checked
- Add a new view on the Woocommerce account page
- How do I add a predefined class to a custom html element?
- How to identify which php file a plugin is using on page load?
- Redirect User when they click Menu Option
- How to separate the taxonomies list from the form so that editing taxonmies is the same as pages and posts?
- Redirect user role to a specific page on login in a multisite network?
- How to add a full working piece of website already coded, to a large scale Website design project?
- Create custom admin page with custom text fields
- Remove node from multisites?
- custom field – changing an element or background of id div – different versions not working
- Multisite – Display different header content based on which site is accessed
- How to get php file based on URL in WordPress
- How can I customize a WordPress theme before it’s downloaded?
- Replace Underscore (_) on Space ( )
- Why isn’t my custom Javascript showing up in my custom template?
- A Customizer checkbox control that sets the setting to “” or to “blank” and show() or hide() a color control
- PHP call div with function
- Add the “.current-menu-item” class to tag?
- Where can I find the code for the menu page meta boxes?
- WordPress causing all code to be displayed on line 1. Receiving multiple errors after cleaning cookies and cache
- Nav Menu Display
- wp_head makes my custom page template not work in Customizer?
- HTML in PHP problem [closed]
- Woocommerce linking variations
- How to continuously developing a WP site that is already deployed in production without damaging it during development
- hello can you advise how to fix the error?
- Add multiple HTML attributes to an Elementor button
- fetch from an external api call and display results in page
- Restricting page by user role