Adds links to navigate to the next and previous posts when editing a post in the WordPress admin.
This plugin adds “← Previous” and “Next →” links to the “Edit Post” admin page if a previous and next post are present, respectively. The link titles (visible when hovering over the links) reveal the title of the previous/next post. The links link to the “Edit Post” admin page for the previous/next posts so that you may edit them.
By default, a previous/next post is determined by the next lower/higher valid post based on the date the post was created and which is also a post the user can edit. Other post criteria such as post type (draft, pending, etc), publish date, post author, category, etc, are not taken into consideration when determining the previous or next post.
Users can customize how post navigation ordering is handled via the “Screen Options” panel available at the top of every page when editing a post. A dropdown presents options to order navigation by: ‘ID’, ‘menu_order’, ‘post_date’, ‘post_modified’, ‘post_name’, and ‘post_title’. Post navigation can further be customized via filters (see Filters section).
NOTE: Be sure to save the post currently being edited (if you’ve made any changes) before navigating away to the previous/next post!
Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage
The plugin is further customizable via six filters. Such code should ideally be put into a mu-plugin or site-specific plugin (which is beyond the scope of this readme to explain).
The ‘c2c_admin_post_navigation_orderby’ filter allows you to change the post field used in the ORDER BY clause for the SQL to find the previous/next post. By default this is ‘post_date’ for non-hierarchical post types (such as posts) and ‘post_title’ for hierarchical post types (such as pages). If you wish to change this, hook this filter. Note: users can customize the post navigation order field for themselves on a per-post type basis via “Screen Options” (see FAQ and screenshot for more info).
Arguments:
Example:
/** * Modify how Admin Post Navigation orders posts for navigation by changing the * ordering of pages by 'menu_order'. * * @param string $field The field used to order posts for navigation. * @param string $post_type The post type being navigated. * @param int $user_id. The user's ID. * @return string */ function custom_order_apn( $field, $post_type, $user_id ) { // Only change the order for the 'page' post type. if ( 'page' === $post_type ) { $field = 'menu_order'; } return $field; } add_filter( 'c2c_admin_post_navigation_orderby', 'custom_order_apn', 10, 3 );
The ‘c2c_admin_post_navigation_post_statuses’ filter allows you to modify the list of post_statuses used as part of the search for the prev/next post. By default this array includes ‘draft’, ‘future’, ‘pending’, ‘private’, and ‘publish’. If you wish to change this, hook this filter. This is not typical usage for most users.
Arguments:
Example:
/** * Modify Admin Post Navigation to allow and disallow certain post statuses from being navigated. * * @param array $post_statuses Post statuses permitted for admin navigation. * @param string $post_type The post type. * @return array */ function change_apn_post_status( $post_statuses, $post_type ) { // Add a post status. // Note: by default these are already in the $post_statuses array: 'draft', 'future', 'pending', 'private', 'publish' $post_statuses[] = 'trash'; // Remove post status(es). $post_statuses_to_remove = array( 'draft' ); // Customize here. if ( 'page' === $post_type ) { $post_statuses_to_remove[] = 'pending'; } foreach ( $post_statuses_to_remove as $remove ) { if ( false !== $index = array_search( $remove, $post_statuses ) ) { unset( $post_statuses[ $index ] ); } } return array_values( $post_statuses ); } add_filter( 'c2c_admin_post_navigation_post_statuses', 'change_apn_post_status', 10, 2 );
The ‘c2c_admin_post_navigation_post_types’ filter allows you to modify the list of post_types used as part of the search for the prev/next post. By default this array includes all available post types. If you wish to change this, hook this filter.
Arguments:
Examples:
/** * Modify Admin Post Navigation to only allow navigating strictly for posts. * * @param array $post_types Post types that should have admin post navigation. * @return array */ function change_apn_post_types( $post_types ) { return array( 'post' ); } add_filter( 'c2c_admin_post_navigation_post_types', 'change_apn_post_types' ); /** * Modify Admin Post Navigation to disallow navigation for the 'recipe' post type. * * @param array $post_types Post types that should have admin post navigation. * @return array */ function remove_recipe_apn_post_types( $post_types ) { if ( isset( $post_types['recipe'] ) ) { unset( $post_types['recipe'] ); // Removing a post type } return $post_types; } add_filter( 'c2c_admin_post_navigation_post_types', 'remove_recipe_apn_post_types' );
The ‘c2c_admin_post_navigation_prev_text’ filter allows you to change the link text used for the ‘Previous’ link. By default this is ‘← Previous’.
Arguments:
Example:
/** * Changes the text for the 'previous' link to 'Older' output by the Admin Post Navigation plugin. * * @param string $text The text used to indicate the 'next' post. * @return string */ function my_c2c_admin_post_navigation_prev_text( $text ) { return 'Older'; } add_filter( 'c2c_admin_post_navigation_prev_text', 'my_c2c_admin_post_navigation_prev_text' );
The ‘c2c_admin_post_navigation_next_text’ filter allows you to change the link text used for the ‘Next’ link. By default this is ‘Next →’.
Arguments:
Example:
/** * Changes the text for the 'next' link to 'Newer' output by the Admin Post Navigation plugin. * * @param string $text The text used to indicate the 'next' post. * @return string */ function my_c2c_admin_post_navigation_next_text( $text ) { return 'Newer'; } add_filter( 'c2c_admin_post_navigation_next_text', 'my_c2c_admin_post_navigation_next_text' );
The ‘c2c_admin_post_navigation_display’ filter allows you to customize the output links for the post navigation.
Arguments:
Example:
/** * Change the markup displayed by the Admin Post Navigation plugin. * * @param string $text The text being output by the plugin. * @return string */ function override_apn_display( $text ) { // Simplistic example. You could preferably make the text bold using CSS. return '<strong>' . $text . '</strong>'; } add_filter( 'c2c_admin_post_navigation_display', 'override_apn_display' );
admin-post-navigation.zip
inside the /wp-content/plugins/
directory for your site (or install via the built-in WordPress plugin installer)admin-post-navigation.zip
inside the /wp-content/plugins/
directory for your site (or install via the built-in WordPress plugin installer)See the Filters section for the c2c_admin_post_navigation_orderby
filter, which has just such an example.
Yes. See the Filters section for the c2c_admin_post_navigation_prev_text
and/or c2c_admin_post_navigation_next_text
filters, which have just such examples. To change or amend the overall markup for the links, look into the c2c_admin_post_navigation_display
filter.
$user_id
arg to get_post_type_orderby()
, and use it, to take into account user preference.$user_id
arg to ‘c2c_admin_post_navigation_orderby’ filter.get_setting_name()
helper function for getting the setting name for the given post type.screen_settings()
to output the dropdown.save_screen_settings()
to save user’s preference.is_valid_orderby()
helper function to verify a given orderby value is valid.get_post_statuses()
for getting post statuses valid for navigation of a given post type.get_post_type_orderby()
.is_post_type_navigable()
.get_the_title()
instead of the_title_attribute()
to get post titles.$user_id
arg to ‘c2c_admin_post_navigation_post_statuses’ filter.sprintf()
to format output markup rather than concatenating strings, variables, and function calls.WP_TESTS_DIR
to /tmp/wordpress-tests-lib
rather than erroring out if not defined via environment variable.the_title_attribute()
to get post title for use in attribute.add_css()
and add_js()
.