Some Advanced WordPress Points

1. Activate a custom function when wp-admin will call:
We are WordPress Developer wants to put some custom functionality or call some custom steps when an administrator is working on wp-admin in other sense when wp-admin is active . It’s simple , just put the following line on your plugin page or active theme “function.php” page.

//Activate the hook
add_action( 'admin_init', 'my_custom_function' );
//Define the custom function
Function my_custom_function()
//your statement/s;

2. How to disable Add New Post / Page / Custom Post Type ?
Ans: It’s very simple , you can disable add new option from wp-admin of post / page or your custom post type by activate a hook for “admin_menu”. Here is the solution:

function disable_new_posts() {
    // Hide sidebar link
    global $submenu;

    // Hide link on listing page
    if (isset($_GET['post_type']) && $_GET['post_type'] == 'post') {
        echo '

‘; } } add_action(‘admin_menu’, ‘disable_new_posts’);

In the above example you could find that the post type is “post” . You can change it post / page/ [your custom post type] . That’s it.
3. How to disable Edit, View, Quick Edit, Trash option from post listing page in wordpress admin area?
Ans: Sometime we don’t want to give the facility to edit / delete/ quick edit from post / page listing section under wordpress admin area even to an administration. Here is the solution for it , just using filter option of wordpress :

add_filter( 'post_row_actions', 'remove_row_actions', 10, 1 );
function remove_row_actions( $actions )
    if( get_post_type() == 'post' )
        unset( $actions['edit'] );
        unset( $actions['view'] );
        unset( $actions['trash'] );
        unset( $actions['inline hide-if-no-js'] );
    return $actions;

remove_row_actions() function works on All Post , All Page , Custom Post Type Listing Page . It will hide Edit , Trash , View, Quick Edit Option from the listing page every after post title. You can check by the changing of get_post_type() return value.

One thought on “Some Advanced WordPress Points”

Leave a Reply

Your email address will not be published. Required fields are marked *

Result of *Captcha loading...