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.

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

share|improve this question
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 Apr 12 '13 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 Apr 12 '13 at 6:31
    
You can try and set 'rewrite' => array('slug' => 'false' for the CPT or set it to / or #, worth a try –  Wyck Apr 12 '13 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? –  songdogtech Apr 12 '13 at 12:58
    
I don't think so without some major hacking around. –  Wyck Apr 13 '13 at 6:17

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
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. –  songdogtech Apr 14 '13 at 19:21

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.