Hide permalink and preview button and link on custom post

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!

Leave a Comment