6

anyone know how to custom box that contain "Publish,save draft,and preview button" ? i'll hide all button except Publish button. and same as "change permalink" also "view,delete,edit" link inside post how to hide the permalink and view link ?

here the illustration what i talking about.

Customizing Publish Button From Original Wordpress

enter image description here enter image description here

Customizing post link from original wordpress

enter image description here enter image description here

delete permalink under wordpress post title

enter image description here

9

You can accomplish the above using hooks. Use the code below in your active theme's functions.php file to get this work

delete permalink under wordpress post title

add_filter( 'get_sample_permalink_html', 'wpse_125800_sample_permalink' );
function wpse_125800_sample_permalink( $return ) {
    $return = '';

    return $return;
}

Customizing post link from original wordpress

add_filter( 'page_row_actions', 'wpse_125800_row_actions', 10, 2 );
add_filter( 'post_row_actions', 'wpse_125800_row_actions', 10, 2 );
function wpse_125800_row_actions( $actions, $post ) {
    unset( $actions['inline hide-if-no-js'] );
    unset( $actions['view'] );

    return $actions;
}

Customizing Publish Button From Original Wordpress

Below has room for improvement, I couldn't get the hooks to do the following, so used css way to hide it.

global $pagenow;
if ( 'post.php' == $pagenow || 'post-new.php' == $pagenow ) {
    add_action( 'admin_head', 'wpse_125800_custom_publish_box' );
    function wpse_125800_custom_publish_box() {
        if( !is_admin() )
            return;

        $style = '';
        $style .= '<style type="text/css">';
        $style .= '#edit-slug-box, #minor-publishing-actions, #visibility, .num-revisions, .curtime';
        $style .= '{display: none; }';
        $style .= '</style>';

        echo $style;
    }
}

NOTES

Additional conditional statement in my case, here i've already solved for the conditional statement

global $pagenow;
if( 'edit.php' == $pagenow && isset($_GET['page_type']) == 'my-custom-post' ){
     // here i use delete post row function that explained by Maruti Mohanty on my custom post 
}

also conditional statement for add new post and custom publish metabox settings

global $pagenow;
    if( 'page-new.php' == $pagenow && isset($_GET['page_type']) == 'my-custom-post' ){
         // here i use add new post and custom publish metabox function
    }

let me know if there have another explanation.

thanks!

  • hey thanks for your answer already try it, but when i've add conditional function if($post->post_type == 'my-post'){ //unset code } its working on my custom post but in the default wordpress post are disapear. – user3073032 Dec 9 '13 at 13:46
  • also for permalink the permalink are disapear like what i want but there is have get shortlink button – user3073032 Dec 9 '13 at 13:47
  • thanks !! already fix it, but not sure about get shortlink button, still havnt solved.. – user3073032 Dec 9 '13 at 14:43
  • @user3073032 Edited the answer, now it should remove the shortlink too. Added #edit-slug-box to the last function – Maruti Mohanty Dec 9 '13 at 14:58
  • @user3073032 Sorry, By mistake I have rejected the edit you have made previously. If you still want to add something, you can do it now, I will review it and add the necessary. – Maruti Mohanty Dec 9 '13 at 15:23
11

I just stumbled across this question and thought I'd share my most common solution which may not work for everyone in all scenarios but I believe this is the most efficient way to achieve the desired results.

When you register a CPT that does not require a single-view output in your theme or plugin, simply define the property 'public' => false,

For example a typical CPT registration might look something like this:

<?php 

/**
 * Custom Post Type: cw-programs (programs)
 * Theme: Your Custom Theme
 * Desc: A custom WP theme
 *
 * @package custom-wp-theme
 * @since   1.0.0
 * @version 1.0.0
 */
function mycpt_content_type_name() {
  $labels = array(
    'name' => __( 'My CPT'),
    'singular_name' => __( 'My CPT' ),
    'add_new' => _x('Add New', 'My CPT'),
    'add_new_item' => __('Add New My CPT'),
    'edit_item' => __('Edit My CPT'),
    'new_item' => __('New My CPT'),
    'view_item' => __('View My CPT'),
    'search_items' => __('Search My CPT'),
    'not_found' =>  __('No My CPT found'),
    'not_found_in_trash' => __('No My CPT found in Trash'), 
    );
    $args = array(
    'labels' => $labels,
    'menu_icon' => 'dashicons-clipboard',
    'public' => false,
    'publicly_queryable' => false,
    'show_ui' => true, 
    'query_var' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'menu_position' => null,
    'rewrite' => array('slug' => __( 'mycpt' )),
    'supports' => array('title', 'editor'),
    'show_in_menu' => false
    ); 

    register_post_type(__( 'cw-program' ),$args);
}

add_action( 'init', 'mycpt_content_type_name' );

In one-fell-swoop, this should remove the view, slug and preview changes links from all associated admin screens. I like This solution, because it does not require any additional functions and the logic is defined in the same place as your cpt (obviously). Hope that this helps others out there, looking for a similar solution.

  • This should be the accepted answer. I knew of public, but didn't know you could also set show_ui to true. That combo is perfect. – Tim Jan 21 '16 at 2:02
  • @Tim A great place to experiment with CPT is using the CPT generator at generatewp.com/post-type You'll find all options with (some) explanation. – pixeline Feb 18 '16 at 10:06
1

We can remove the Post preview, view and permalinks field by setting publicly_queryable argument to false.

setting **publicly_queryable** argument to false

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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