Create a “Dummy” parent page for a hierarchy in page listing?

OK here is my attempt, it is pretty hacky and in the end I was not able to remove the link/color of the parent item, but the parent link will not work.. so it kinda works.

First create a CPT with the following params set:

$args = array( 
        'hierarchical'        => true,
        'public'              => false,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'capability_type'     => 'post', 
        'supports'            => array( 'title','page-attributes' ),
    );

Fill in the rest as needed, this will enable you to have a parent post/page that shows in the admin but not on the front end, it also allows parent functionality via page-attributes.

Now we can throw in a filter that removes the small “edit”, “view” and “trash” links for the parent.

function wpse_95518($actions) {

    global $post;

    //rename this to your CPT 
    if ($post->post_type =="parent"){
        // check if it's a parent
        if ( ! (is_post_type_hierarchical('parent') && $post->post_parent )) {

            unset( $actions['inline hide-if-no-js']);
            unset( $actions['trash'] );
            unset( $actions['view'] );  
            unset( $actions['edit'] );
        }           
        return $actions;
    }
    return $actions; 
}

add_filter('page_row_actions', 'wpse_95518');

Now things get a bit funky, to remove the parent title link functionality to edit the post.

function wpse_removetitle_95518($action){

    global $post; 

    if ($post->post_type =="parent"){
        if ( is_post_type_hierarchical('parent') && $post->post_parent ) {
            return $action;
        }else{
            return '#'; //just in case
        }
    }
    return $action;
 }
add_filter( 'get_edit_post_link', 'wpse_removetitle_95518');

Now parent items of the CPT should not be editable via links in the admin, it will show as edit.php?post_type=parent# but the children will be ok.

The downside is that the parent item will still be a blue link instead of black text, I could not find any simple way to remove the link from the title or add custom CSS to do it via javascript without extending the WP List Table.

You can of course alter the parent title using the_title filter but even setting it to NULL via the above conditional still shows a < a href=..>

Also there might be a simpler way to do all of this just using the is_post_type_hierarchical filter.

Github link to Table Class code for the title.

Leave a Comment