get_next_post returns null if there is no post anymore. And then get_permalink will have a null value for $next_post, so it will get the permalink for the current post, resulting in linking to the same post again and again.
You should thus check for null, and if so, link to the first (latest) post.
Something along the lines of (in your code style):
function next_shortcode( $atts ) {
$next_post = get_next_post();
if ( ! is_null($next_post) ) {
return get_permalink( $next_post );
}
$posts = get_posts( 'numberposts=1' );
return $posts[0];
}
Related Posts:
- Making a Shortcode [NEXT] and [PREVIOUS] to place into specific posts for post navigation
- How to make my pagination loop continuously?
- How to change the page break numbering?
- next_post_link for CPT only working for a few posts? weird!
- Why do next pages load the same content rather then older articles?
- Next and Previous Posts of Same Parent
- Pagination for a page created by the shortcode “Product”
- How to use/enable Pagination?
- Displaying the author of next and previous posts in pagination?
- How to exclude or filter password protected posts when using next_post_link() previous_post_link
- query_posts pagination will always show identical content
- WP_Query and pagination AGAIN?
- pagination links not displaying
- WordPress post shortcode pagination not working
- Pagination for custom posts loop
- How to set up posts per page on WP
- wp_link_pages shortcode for ‘nextpagelink’
- Content included from pagination
- WordPress not showing pagination links
- Need help with get_posts pagination
- previous_posts_link returns null when querying custom post type
- pagination/prev and next page links not showing
- convert it into short code & explan how? [closed]
- Enqueue Scripts / Styles when shortcode is present
- Conditionally Loading JavaScript/CSS for Shortcodes
- Can the Next/Prev Post links be ordered by menu order or by a meta key?
- What does extract( shortcode_atts( array( do?
- How do I escape a ‘]’ in a short code?
- Pass boolean value in shortcode
- Show shortcode without executing it
- Shortcode always displaying at the top of the page
- Redirect function inside a Shortcode
- How to create a shortcode with 1 parameter (atts)
- how to show the syntax of a shortcode
- Custom shortcode being executed when saving page in wp-admin
- Change appearance of shortcode text inside editor
- current_shortcode() – detect currently used shortcode
- is it possible to get next_post_link
- shortcodes output before content [duplicate]
- WordPress plugin shortcode not working
- How to add stylesheets only to pages with specific shortcode?
- Using get_option() in JavaScript
- Get Previous & Next posts by Post ID
- Filter next_post_link() and previous_post_link() by meta_key?
- Shortcode empty attribute
- How does a shortcode work?
- Shortcode outputs at the top of the_content
- the_excerpt and shortcodes
- Using wp_editor in shortcode
- Remove wpautop from shortcode content / remove whitespace in buffering
- Get current post id witout passing in shortcode
- Why are you using add_action for shortcode?
- How to get URL param to shortcode?
- How to add multiple buttons to TinyMCE?
- Check if post/page has gallery?
- How can I add title attributes to next and previous post link functions?
- Get first video from the post (both embed and video shortcodes)
- Get shortcode name from within it’s callback function? [duplicate]
- Wordspress add into my javascripts
- How to paginate wordpress [gallery] shortcode?
- How do I create a Shortcode that returns text if domain is .com, not .co.uk
- Using preg_replace to separate gallery from the_content?
- Remove specific shortcode from get_the_content()
- How to display the site name in a WordPress page, or post
- Hide/show content starting in the middle of a paragraph
- Combining shortcode and get_template_part
- How can I put a wp_redirect into a shortcode?
- Escaping quotes from shortcode attributes
- Run visual composer code in php page
- short code output too early
- Shortcode in shortcode: How to append variable?
- Remove wptexturize from a shortcode?
- How can i put an array as variable in shortcode_atts?
- How to get next and previous post links, alphabetically by title, across post types, in a shortcode
- Autoembeds don’t work with paragraphs
- Table of Contents with a shortcode
- Create custom [sourcecode] shortcode, the right way?
- get_adjacent_post alternative on a very large db
- TED talks shortcode not working
- Allowing shortcodes inside attributes
- What is the best way to enable nested shortcodes?
- Tinymce – How to hook before or after live shortcodes rendering?
- How to customize a shortcode using the customizer
- Native “playlist” shortcode random playing… How?
- How to Output HTML tags in do_shortcode?
- List of all inbuilt WordPress shortcodes
- Nested Shortcode Detection
- Shortcode output always showing at top of page
- Organizing shortcodes. How to display all of them and their attributes?
- How to detect if a Shortcode is being called on a page?
- How to get current page title inside a page itself in a shortcode and in page content
- how to have the gallery shortcode output one single UL list instead of several DL?
- Implement If-ElseIf-Else-EndIf with short codes
- Short code to display a loop
- Using shortcode in Post title
- How can I get next/ previous post links to order by a filter (by the last word of the title)?
- using html as shortcode attribute
- shortcode outputs first before the page content [duplicate]
- next and previous post link ordered alphabetically
- How to add ‘class’ attribute into shortcode [audio]?