Disabling Edit Button for Custom Post in the Frontend Only

Support MB Custom Post Type Disabling Edit Button for Custom Post in the Frontend OnlyResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #24797
    MartinMartin
    Participant

    Hi,

    I need to be able to get rid of the standard WP edit button so it doesn't appear on my custom posts.

    I have a custom post type of 'job'. For the appropriate users to be able to use some frontend forms to update custom fields against the job they need the role permissions to edit the post (otherwise instead of the frontend forms I get a box saying the user doesn't have permissions to edit the post).

    I don't want the users to be able to click the Edit button that appears because of this permission level and end up in the Dashboard to actually edit the job post. Their only edit should be by filling in the forms they're given.

    The following code does disable the button completely but it also prevents the Edit option from working in the Dashboard as well so using Snippets I have to deactivate the function when I want to edit the jobs in the Dashboard.

    function wpse_remove_get_edit_post_link( $link ) {
        return null;
    }
    add_filter('get_edit_post_link', 'wpse_remove_get_edit_post_link');

    Is there a better way to either achieve what I'm looking for or an better hook to use for the above function so it only affects the frontend display and not the Dashboard?

    Thanks.

    #24798
    Long NguyenLong Nguyen
    Moderator

    Hi Martin,

    You can use the function is_admin() to check if you are viewing the admin dashboard.

    function wpse_remove_get_edit_post_link( $link ) {
        if ( is_admin() ) return $link;
        return null;
    }
    add_filter('get_edit_post_link', 'wpse_remove_get_edit_post_link');
    #24805
    MartinMartin
    Participant

    Simple and works perfectly. Thanks Long.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.