How to show a Post Edit link on the single post page

Suppose you are running a membership site (or any) and allowing users to edit posts from the frontend or backend, but you don’t want to show the Top Toolbar on the frontend. You can use the below code snippet to provide an “Edit Post” link for your end-users.

/* Show Post Edit Link on the frontend single post page */
add_action('loop_start', function () {
    if (!is_singular() || is_page() || !is_main_query()) {
        return;
    }
 
    edit_post_link(__('Edit Post'));
}, 99);

Here is the output after injecting the snippet.

Note: You need to inject this snippet into your theme/child theme’s functions.php file. Else you can use a third-party plugin like “Code Snippets.”

MM Aurangajeb
MM Aurangajeb

Spreading Happiness. Support Engineer, WordPress Enthusiast, Blogger.

Articles: 18

Newsletter Updates

Enter your email address below and subscribe to our newsletter