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:
- Receiving Stripe Webhooks on a wordpress website
- Integrating WordPress to my website, while keeping my own authentication system
- What would be a PHP command to erase all posts from category X from the last month?
- Add a wp editor to custom plugin and save data
- Walker class: Problems with understanding how walk() method can be called without error
- How to Use the Function is_user_logged_in To Display Different Menus?
- Change comments form title on a page by page basis
- Add value to usermeta without removing previous values?
- Setting up the child theme so as to enable right-to-left WordPress?
- String replace WordPress Site Title
- WordPress Ajax Data problem
- Remove all nav menu classes ( but keep useful ones… )
- Type hinting and void return question
- Customized title tag for each page in pagination?
- Why WordPress architecture is not pure object oriented and it don’t use MVC pattern? [closed]
- How to break down importing of feeds
- How can I add a custom class to only nav sub-menu > li > a items in WordPress?
- items_wrap not working
- Style wp_page_menu() items
- How to create and work with custom data / tables (i.e., for arbitrary data)?
- PHP can I add line numbers to file_get_contents()
- Multiple choice in a custom taxonomy
- Remove one value in dismissed_wp_pointers?
- Accessing data from a non-WP database/table within a page content
- Changing layout with wp_customise
- WP dynamic featured image – Can’t get second featured image url
- Reordering Buddy Press profile navigation [closed]
- Selectbox in admin panel function linking to CSS
- How to hide products that do not have an image from a slider carousel for an ecommerce webpage?
- How to remove role=”navigation” from all nav elements?
- Add New User, extra fields which are required?
- Send an email to specific adress when button is clicked?
- Customizer: active_callback and sanitize_callback incompatibility?
- Redirect specific user role to specific site after login?
- Send multiple attachments with wp_mail in PHP
- custom url rewrite for wordpress
- How to get the value of input hidden html from text editor to custom page template?
- Make a list of sites for each user in WPMU – switch_to_blog (display in SITE_ID: 1)
- Output Video Download Link in template
- how to show only specific category for a template
- How to get private property in parent class into extended class?
- “operation successful” message
- I’m trying to create an array with a foreach loop, but the array only stores the last item [closed]
- Clickable image link sends people to wrong URL
- Function Reference Documenting Template Tags for use in Custom Theme Templates?
- Create page template via functions.php?
- How to include custom PHP file both in header and footer files
- How Do I Find & Remove H1 From Site-Title-Wrapper? [closed]
- 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”
- I want to fusion the product columns in email table order
- 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?
- How To Customize Position of »add to cart« of WooCommerce on Product Page [closed]
- 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
- Custom Navigation Bar JSON Syntax Error in JSON at Position 0