7

Is it possible to set up a "dummy" page - just a page title that appears in the page listing, and a page that is not editable and doesn't have a slug?

This is more of a hypothetical question, as I don't know where to start with code or determine the best way to go.

I'd like to have the option to set up such a parent/child hierarchy in the page listing so that the child pages fall under the parent, but the parent page is just a placeholder and not a real page.

The reason: for users without lots of experience in WordPress, it's helpful to organize pages in a parent/child hierarchy - especially if there are lots of pages - so that that related pages are more organized in the page listing. Users can also visualize building a menu, too, if child pages are organized under a parent. The problem is the parent page can be editable and not part of the established page content, and in my experience, this leads to user confusion.

I can use a function to remove the editor for a specific page and use entires in robots.txt to not index the dummy parent, but that means changing those for a new parent. And that parent page still has a slug, even if blocked wit

So is there a way to create a function that creates a page title and with the ability to assign child pages, but have the parent page unopenable, uneditable and not have a slug?

enter image description here

5
  • 1
    "... a page title and with the ability to assign child pages, but have the parent page unopenable, uneditable and not have a slug?" -- sounds a lot like a custom post type.
    – s_ha_dum
    Commented Apr 12, 2013 at 4:28
  • I don't think there is a way to remove the slug. I forgot if you can show it in the admin but hide it from the front-end, if so you can use some javascript in the back-end to remove the link.
    – Wyck
    Commented Apr 12, 2013 at 6:31
  • You can try and set 'rewrite' => array('slug' => 'false' for the CPT or set it to / or #, worth a try
    – Wyck
    Commented Apr 12, 2013 at 6:40
  • s_ha_dum and Wyck: CPT, good idea; I'll look into that. So non-CPT pages - regular WP pages - can be children of a CPT? Commented Apr 12, 2013 at 12:58
  • I don't think so without some major hacking around.
    – Wyck
    Commented Apr 13, 2013 at 6:17

1 Answer 1

2

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.

1
  • Thanks for all this; it's appreciated. But if non-CPT pages - regular WP pages - can't be children of a CPT, I guess I'd have to change the pages to CPTs. The thing I did for now was make blank parent pages and block them in robots.txt; and then use custom links in the menu with http://# to not use the parents in the menu. Commented Apr 14, 2013 at 19:21

Your Answer

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

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