7

Can someone please assist with how to remove from my theme, whilst in author mode, the edit_post_link (Edit link), throughout all my pages. Which php files in the Twenty Eleven theme (WordPress v3.2) do I need to comment out to no longer display this edit link?

I realise that you only see this during author mode but would like to know how to remove altogether.

Thanks.

5 Answers 5

4

It's the edit_post_link() function. You'll find lines like the following, that you need to comment out:

// from /twentyeleven/content-intro.php
edit_post_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' );
14

One way is to edit the template files of your theme, as you mentioned in your question you are using Twenty Eleven, so you can follow the advice of @kaiser.

The other way that I will prefer instead of modifying the template files is to use the filter. The advantage of filter is it will work with other themes too. The disadvantage of filter is that you will have empty <span></span> tags in your html source, though they won't be visible on the actual page.

You can put the following code in your functions.php.

function wpse_remove_edit_post_link( $link ) {
    return '';
}
add_filter('edit_post_link', 'wpse_remove_edit_post_link');

P.S you can use the filter to disable the edit post link on selective posts too.

3
  • 5
    Or just use add_filter( 'edit_post_link', '__return_false' ); :)
    – kaiser
    Commented Jul 11, 2011 at 15:34
  • 1
    Would add_filter( 'edit_post_link', '__return_null' ); be more appropriate than false?
    – jb510
    Commented Nov 19, 2013 at 2:25
  • 1
    This is better than the accepted solution because you don't need to look for the actual function, which is especially difficult if you use child themes.
    – f055
    Commented Jan 11, 2018 at 15:38
5

Hameedullah's answer is more elegant, but doesn't eliminate the before and after items. To do that, you need to filter get_edit_post_link instead, and return null.

function wpse_remove_get_edit_post_link( $link ) {
    return null;
}
add_filter('get_edit_post_link', 'wpse_remove_get_edit_post_link');
1
  • this also kills the edit link in the admin area!
    – jasie
    Commented Apr 2, 2020 at 8:45
1

Here is a one liner. add_filter('edit_post_link', '__return_false');
Bonus: Hide admin bar add_filter('show_admin_bar', '__return_false');

0

Hiding the edit post link from those who aren't administrators.

// Hide the Edit Post Link from Non Administrators Start.

function prefix_remove_get_edit_post_link( $link ) {
    if(current_user_can('administrator')) {
        return $link;
    }
    return null;
}

add_filter('get_edit_post_link', 'prefix_remove_get_edit_post_link');

// Hide the Edit Post Link from Non Administrators End.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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