Title: function not executing
Last modified: December 25, 2020

---

# function not executing

 *  Resolved [fasihsajid](https://wordpress.org/support/users/fasihsajid/)
 * (@fasihsajid)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/function-not-executing-2/)
 * hello I am turning a PHP into a function to be executed on a page template, the
   code when itself is run through directly from the template file works but when
   I create a function in code snippets and call it on the page template it breaks
   
   this is the code
 *     ```
       function getPrevNext(){
       $pagelist = get_pages("child_of=".$post->post_parent."&parent=".$post->post_parent."&sort_column=menu_order&sort_order=asc");
       	$pages = array();
       	foreach ($pagelist as $page) {
       	   $pages[] += $page->ID;
       	}
   
       $current = array_search($post->ID, $pages);
       	$prevID = $pages[$current-1];
       	$nextID = $pages[$current+1];
   
       	echo '<div class="navigation">';
   
       	if (!empty($prevID)) {
       		echo '<div class="alignleft">';
       		echo '<a href="';
       		echo get_permalink($prevID);
       		echo '"';
       		echo 'title="';
       		echo get_the_title($prevID); 
       		echo'">Previous</a>';
       		echo "</div>";
       	}
       	if (!empty($nextID)) {
       		echo '<div class="alignright">';
       		echo '<a href="';
       		echo get_permalink($nextID);
       		echo '"';
       		echo 'title="';
       		echo get_the_title($nextID); 
       		echo'">Next</a>';
       		echo "</div>";		
       	}
       }
       ```
   

Viewing 1 replies (of 1 total)

 *  Plugin Author [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * (@bungeshea)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/function-not-executing-2/#post-14165524)
 * I’d recommend making this into a shortcode:
 *     ```
       add_shortcode( 'prev_next', function () {
       	ob_start();
   
       	getPrevNext();
   
       	return ob_get_clean();
       } );
       ```
   
 * Then use `[prev_next]` in your post or page content, or call `do_shortcode( '[
   prev_next]' );` in your template files.

Viewing 1 replies (of 1 total)

The topic ‘function not executing’ is closed to new replies.

 * ![](https://ps.w.org/code-snippets/assets/icon.svg?rev=2148878)
 * [Code Snippets](https://wordpress.org/plugins/code-snippets/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/code-snippets/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/code-snippets/)
 * [Active Topics](https://wordpress.org/support/plugin/code-snippets/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/code-snippets/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/code-snippets/reviews/)

## Tags

 * [functions](https://wordpress.org/support/topic-tag/functions/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [snippet](https://wordpress.org/support/topic-tag/snippet/)

 * 1 reply
 * 2 participants
 * Last reply from: [Shea Bunge](https://wordpress.org/support/users/bungeshea/)
 * Last activity: [5 years, 3 months ago](https://wordpress.org/support/topic/function-not-executing-2/#post-14165524)
 * Status: resolved