Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to add an option to create a child page from the wordpress all pages screen. I found this link, but cannot get it working properly. It is exactly what I need, but I need help fixing it

http://sltaylor.co.uk/blog/easy-child-page-creation-wordpress/

function slt_childPageAction( $actions, $page ) {  
    $actions["create-child"] = '<a href="/wp-admin/post-new.php?post_type=page&amp;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' );  
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

If you mean the 404 error:

function slt_childPageAction( $actions, $page ) {
    $actions["create-child"] = '<a href="'.add_query_arg(array('post_type' => 'page', 'parent_id' => $page->ID), admin_url('post-new.php')).'" 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"] ) )
        echo '<script type="text/javascript">jQuery( document ).ready( function($) { $("#parent_id").val("' . (int)$_GET["parent_id"] . '"); } );</script>';
}
add_action( 'edit_page_form', 'slt_setChildPage' );

(the url path to /wp-admin/ was hard-coded)

nice find btw :)

share|improve this answer
    
Great! works like a charm. Do you know how I could have this show up only on top level parent pages? –  Shae Sep 21 '11 at 17:18
    
Add a conditional check in the 1st function: if($page->post_parent == 0) –  onetrickpony Sep 21 '11 at 18:21
    
Perfect! Thanks for the help! –  Shae Sep 21 '11 at 18:33
    
One thing I noticed, the add child link shows up on all types. ex., all trash items, and some plugins using custom post types. How can you show this only on pages? –  Shae Sep 22 '11 at 19:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.