Title: Need help editing function
Last modified: August 21, 2016

---

# Need help editing function

 *  Resolved [dubbinz](https://wordpress.org/support/users/dubbinz/)
 * (@dubbinz)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/need-help-editing-function/)
 * I have a code snippet which I placed in my functions.php The function adds next/
   previous to posts using shortcodes
 * here is the code
 *     ```
       add_shortcode( 'prev', 'prev_shortcode' );
       add_shortcode( 'next', 'next_shortcode' );
       function next_shortcode($atts) {
           global $post;
           ob_start();
           next_post_link( '<div class="nav-next">%link</div>', 'Next post link' );
           $result = ob_get_contents();
           ob_end_clean();
           return $result;
       }
   
       function prev_shortcode($atts) {
           global $post;
           ob_start();
           previous_post_link( '<div class="nav-previous">%link</div>', 'Previous post link' );
           $result = ob_get_contents();
           ob_end_clean();
           return $result;
       }
       ```
   
 * What I want to do is edit this code so it only cycles through one category in
   date order which I assume is default anyway. I am limited in my ability with 
   php so I need help to accomplish what I want. can anyone help?

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [Shaun Scovil](https://wordpress.org/support/users/sscovil/)
 * (@sscovil)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/need-help-editing-function/#post-3860392)
 * Here you go:
 *     ```
       add_shortcode( 'prev', 'prev_shortcode' );
       add_shortcode( 'next', 'next_shortcode' );
       function next_shortcode($atts) {
           global $post;
           ob_start();
           next_post_link( '<div class="nav-next">%link</div>', 'Next post link', true );
           return ob_get_clean();
       }
   
       function prev_shortcode($atts) {
           global $post;
           ob_start();
           previous_post_link( '<div class="nav-previous">%link</div>', 'Previous post link', true );
           return ob_get_clean();
       }
       ```
   
 *  [Shaun Scovil](https://wordpress.org/support/users/sscovil/)
 * (@sscovil)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/need-help-editing-function/#post-3860393)
 * There is an optional third parameter in [next_post_link()](http://codex.wordpress.org/Function_Reference/next_post_link)
   and [previous_post_link()](http://codex.wordpress.org/Function_Reference/previous_post_link)
   to indicate whether the next/prev post must be within the same category as the
   current post. Default is false.
 *  Thread Starter [dubbinz](https://wordpress.org/support/users/dubbinz/)
 * (@dubbinz)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/need-help-editing-function/#post-3860398)
 * [@shaun](https://wordpress.org/support/users/shaun/) Scovil
    like I said I have
   no idea how to edit it so I completely confused by the response. I know that 
   the changes I need have to be in the () but I have no idea what to put or how
   to edit it.
 * Can you give me an example of the edited version of the code snippet so i can
   understand?
 *  [Shaun Scovil](https://wordpress.org/support/users/sscovil/)
 * (@sscovil)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/need-help-editing-function/#post-3860400)
 * Just replace your old code (the whole thing from your first post) with my code(
   the whole thing from my response).
 *  [Shaun Scovil](https://wordpress.org/support/users/sscovil/)
 * (@sscovil)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/need-help-editing-function/#post-3860403)
 * Specifically, I changed this:
 * `next_post_link( '<div class="nav-next">%link</div>', 'Next post link' );`
 * …to this:
 * `next_post_link( '<div class="nav-next">%link</div>', 'Next post link', true );`
 * …for both the next and previous post functions.
 * I also cleaned up the code a bit, using `ob_get_clean()` instead of all that `
   $result` business. But that was just an added bonus. 🙂
 *  Thread Starter [dubbinz](https://wordpress.org/support/users/dubbinz/)
 * (@dubbinz)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/need-help-editing-function/#post-3860418)
 * [@shaun](https://wordpress.org/support/users/shaun/) Scovil sorry shaun but when
   I responded I only saw your 2nd post, for whatever reason I couldn’t see your
   first response so I was immediately confused. thanks for the help.
 *  Thread Starter [dubbinz](https://wordpress.org/support/users/dubbinz/)
 * (@dubbinz)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/need-help-editing-function/#post-3860453)
 * This is now resolved
 *  [Shaun Scovil](https://wordpress.org/support/users/sscovil/)
 * (@sscovil)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/need-help-editing-function/#post-3860455)
 * Glad I could help!

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Need help editing function’ is closed to new replies.

## Tags

 * [next](https://wordpress.org/support/topic-tag/next/)
 * [pagination](https://wordpress.org/support/topic-tag/pagination/)
 * [previous](https://wordpress.org/support/topic-tag/previous/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 2 participants
 * Last reply from: [Shaun Scovil](https://wordpress.org/support/users/sscovil/)
 * Last activity: [12 years, 11 months ago](https://wordpress.org/support/topic/need-help-editing-function/#post-3860455)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
