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
- Get Previous & Next posts by Post ID
- Shortcode outputs at the top of the_content
- Combining shortcode and get_template_part
- Escaping quotes from shortcode attributes
- How to get current page title inside a page itself in a shortcode and in page content
- Short code to display a loop
- How can I get next/ previous post links to order by a filter (by the last word of the title)?
- How can I just get content inside a shortcode or just outside
- Custom Shortcode AJAX 400 Bad Request
- WordPress core responsive video not working with shortcode
- conditional shortcode not working
- Wraping $content into link with shortcodes
- WordPress previous_post_link exclude posts with multiple categories
- Simple contact form with field validation
- Next and Previous links on a single taxonomy page only link to same term
- other shortcodes in Contact form 7 MAILS [closed]
- Remove empty p-Tags in Shortcode content before non p-Tags
- What is a short code?
- Wrap shortcode inside custom block
- Instagram URL is converted into oEmbed
- Shortcode with no attribute but has value
- Remove wpautop from specific shortcodes only
- Can I use get_adjacent_post for specific categories?
- basic shortcode – Why 1st paragraph not wrapped in p tag, but 2nd is
- unwanted P tags in shortcode, delay wpautop not working
- Shortcodes and a list of IDs?
- Shortcode adding plugin output before post, instead of inline [duplicate]
- Include tags in the body of a post
- no content after shortcode
- Remove shortcodes that are different (but same pattern) in each post
- Place a URL parameter value inside a WordPress short code
- Shortcodes in excerpts returning empty string
- Scripts for shortcode: concatenate or load separately? [closed]
- Print shortcode in defined area
- WordPress shortcodes are not working
- Wrap Shortcodes and wpautop
- Shortcode called twice
- Favorite websites with shortened hyperlinks
- Best way to find all shortcodes that come with WordPress
- Using Variables in Shortcodes
- next_post_link / previous_post_link not working with WP_Query
- Add JS in footer via shortcode?
- Shortcode syntax errors
- Single.php Category Post Count
- Passing variable in nested shortcodes
- How to transform WordPress user role code to WP shortcode?
- Does short-code slow down my WordPress site?
- redirect if shortcode exists
- Position shortcode off [duplicate]
- How to use a nested shortcode to render the value of an attribute in parent shortcode
- ob_get_clean(); doesn’t return $value in shortcode?
- Content between shortcodes
- Parsing a shortcode through an author meta textfield
- Adding YouTube button to TinyMCE editor
- How to find out what handler is registered to a shortcode
- tiny_mce_before_init preventing custom shortcode icon appearing
- Custom Fields – Boolean Display of True/False to Yes/No
- How to display NextGEN gallery in templates?
- Twitter bootstrap tabs
- Ajax (jquery) wp_query pagination returns -1
- jQuery Tabs in Shortcode API
- Echo Extra Shortcode HTML to wp_foot
- How can I use a plugin shortcode inside of a html form?
- Disable wpautop on Shortcode attributes
- remove shortcode pagination for specific url referrer
- Shortcode PHP file for two conditions passed when do shortcode
- update_metadata() appends shortcode data for every page refresh
- Using previous_post_link next_post_link but with a filter on a custom field
- Add audio file to post using custom term meta field as link [closed]
- Display tags cloud from a specific category ID with a shortcode
- How to list child pages with excerpts, e.g. [child-pages depth=”1″ excerpt=”1″]
- Video shortcode outside WordPress not working with IE and mediaelement’s Flash fallback
- Inserting a variable into a shortcode inside php
- Clarify: Enqueueing scripts within shortcode only loads in footer?
- Create plugin/function to catch XML-data via Shortcode
- Retrieving next_post_link() and previous_post_link() in functions.php
- how to implement next/prev within category archive?
- Shortcode conversion to hrml when post is published