Custom Fields
Re-Envisioned
Support MB Custom Post Type Disabling Edit Button for Custom Post in the Frontend Only

  • Creator
    Topic
  • #24797
    Resolved Martin
    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #24798
    Long 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
    Martin
    Participant

    Simple and works perfectly. Thanks Long.

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