1

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' );  

1 Answer 1

0

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 :)

3
  • Great! works like a charm. Do you know how I could have this show up only on top level parent pages?
    – Shae
    Sep 21, 2011 at 17:18
  • Add a conditional check in the 1st function: if($page->post_parent == 0) Sep 21, 2011 at 18:21
  • 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, 2011 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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