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:
- 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
- In PHP how do I make my navigation bar show certain links to admins only?
- Removing “There is no account with that username or email address.” error message in “/wp-login.php?action=lostpassword”
- Integrate otp in my custom singup form
- Woocommerce template file outputting tags
- Hide A Class and Add Custom HTML Code Using WordPress
- Featured image in menu wordpres
- Trying to update Woocommerce meta values
- How do I know if the user is a customer?
- How to block specific user id in custom login form?
- I want to show cart items number if any or nothing, simple CART text
- update_user_meta as multiple value but with same meta key
- I want to fusion the product columns in email table order
- retrieve “Link Color” value
- How to set Nav as a default menu in wordpress
- Inserting a class on before_widget if checkbox is checked
- If Statement is Ignored?
- Add a new view on the Woocommerce account page
- Having trouble creating two shortcodes, one for logged in user and one for visitors
- Delete post meta by serialized meta value
- How do I add a predefined class to a custom html element?
- How can I update the price when someone enters postcode or zip code in woocommerce checkout page?
- How to identify which php file a plugin is using on page load?
- Adding new divs with custom classes to products on WooCommerce shop page [closed]
- Dynamic “home” image and URL based on current folder
- Dynamic Banner Text based on Subdomain
- Create “blank” admin page without having admin-bar/admin-menu for faster load
- Redirect User when they click Menu Option
- Need help transforming echo to return for use with shortcode
- How to separate the taxonomies list from the form so that editing taxonmies is the same as pages and posts?
- Noob question: want to remove the “site identity” logo for specific part of website only
- Create Schema in WordPress with PHP
- Redirect after login depending on the URL
- Create form which redirects to site in network?
- 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?
- Redirecting the lost password page request when using a custon login page
- Add custom attribute to product’s HTML to woocommerce cart page
- Create custom admin page with custom text fields
- Autoloading Classes in Plugins
- Remove specific javascript when viewing page in Customizer?
- Search only for posts with specific metadata?
- Running local copy of an old WordPress site on MAMP
- Remove node from multisites?
- Automatically refresh page if widget is added to page?
- How to create a sub-page of sub-page?
- custom field – changing an element or background of id div – different versions not working
- Real time notification on user profile after new comment
- Customizing WooCommerce with PHP
- How to add text before posts
- Multisite – Display different header content based on which site is accessed
- How to get php file based on URL in WordPress
- Add two or multiple functions in WordPress Post or Page
- What image is this pulling?
- How can I customize a WordPress theme before it’s downloaded?
- Show content by using tags
- How to associate dynamic PHP page for chosen WordPress tag?
- Only display notification on single post
- Is there a way to have chunks of a page’s content expire?
- index.php navigation
- Replace Underscore (_) on Space ( )
- Where can I find the declaration of `$_wp_theme_features`?
- Static home page ignored
- How do I routinely extract the thumbnail of the most recent post?
- Why isn’t my custom Javascript showing up in my custom template?
- Showing the project type in HREF
- WordPress error on my website
- Display tab title as ‘blog tagline | blog title’
- A Customizer checkbox control that sets the setting to “” or to “blank” and show() or hide() a color control
- My customizer’s setting doesn’t set to the default and needed to click the control’s “Default” button before it’ll be set
- PHP call div with function
- Use custom get results query to show posts WordPress
- Showing custom field contents without listing description
- How can I show only if custom field has content [closed]
- media-uploader insert into post is not inserting
- How to use PHP code with wordpress page
- Best way to define a database with product codes and back-end support?
- How to show all of aspecific post type that has taxonomy and a specific term
- wp_customize_image_control default value
- Check if values exists DB
- How to hide something from custom home page with php code?
- Add the “.current-menu-item” class to tag?
- if is_bbPress register jquery
- Auto create description in post
- Pagination on Custom Loop
- How To Customize Position of »add to cart« of WooCommerce on Product Page [closed]
- Widget header unique classes
- why is this content-template not showing any of my blog-entries?
- Add multiple HTML attributes to an Elementor button
- Custom Navigation Bar JSON Syntax Error in JSON at Position 0
- Nav menù doesn’t display selected pages
- Woocomerce custom add to cart button edit functionality [closed]
- Capture the Selected Radio Button Value between two files in wordpress theme
- fetch from an external api call and display results in page
- Partial refresh in WordPress live preview
- How to change product title color in shop page if product has specific product tag (Woocommerce)?
- How to capture number input from wordpress form into acf field in woocommerce
- Restricting page by user role
- Add More Featured Data Not Sending to Database