Skip to navigation | Skip to content



Easy child page creation for WordPress

Here’s a quickie that can help with WordPress sites that have a lot of pages. If some of the pages have longish titles, the “Parent Page” drop-down on the edit page screen can get unwieldy. The scroller for the drop-down can run off the right side of the screen.

OK, it’s fine (often easier) to use the keyboard to navigate drop-downs. But not everyone knows how to, and even so, with a large amount of pages, selecting the right parent can become a pain.

I think I adapted the following code from a plugin or someone else’s post. Thanks whoever you are, but frankly I’m so busy at the moment I’ve forgotten where it came from! Anyway, if you drop the following into your custom theme’s functions.php, you’ll get a new “Create child” link under every page listed in WP admin, when you hover over the title:

function slt_childPageAction( $actions, $page ) {
	$actions["create-child"] = '<a href="/wp-admin/page-new.php?parent_id=' . $page->ID . '" title="Create a new page with this page as its parent">Create child</a>';
	return $actions;
}
add_filter( 'page_row_actions', 'slt_childPageAction', 10, 2 );
function slt_setChildPage() {
	global $post;
	if ( $post->post_type == "page" && $post->post_parent == 0 && isset( $_GET["parent_id"] ) && is_numeric( $_GET["parent_id"] ) )
		echo '<script type="text/javascript">jQuery( document ).ready( function($) { $("#parent_id").val("' . $_GET["parent_id"] . '"); } );</script>';
}
add_action( 'edit_page_form', 'slt_setChildPage' );

The first bit adds the page action link. The second bit adds some jQuery to the right edit screen to set the specified parent, if it’s been passed. I couldn’t find another way to set the drop-down… Well, it works!

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Want to show me some code? Don't paste long code here, link to a post at pastebin.ca or a similar site. Thanks.

Recent posts

Archives