Do you want to add an edit post link to your WordPress posts and pages?
Adding an edit post link lets you quickly go to the post edit screen from the front of your site to make changes.
Why Add an Edit Post Link to WordPress Posts and Pages?
Adding an ‘Edit Post’ link helps you make quick and easy changes to your content.
Instead of searching through your posts and pages in your WordPress dashboard, you can simply click the ‘Edit Post’ link on the front of your website. This will open the post or page editor screen directly.
Note: The edit post link will only be visible to users who are logged in and have the proper user role and permissions.
Many WordPress themes have this feature, but sometimes developers remove it. If your theme doesn’t have it, you’ll need to add it manually.
How to Add an Edit Post Link to WordPress Posts and Pages
To add an edit post link to WordPress, you need to add code to your WordPress files.
We’ll show you two methods to add the code to your site:
Method 1: Add an Edit Post Link in WordPress using WPCode (Recommended)
The first method is super easy and doesn’t need any coding experience. But it doesn’t work with all themes, and you won’t control exactly where the link appears.
Method 2: Add an Edit Post Link by Manually Editing Your Theme Files
The second method is more technical. You need to know some PHP to place the code correctly. However, it gives you control over exactly where the edit link appears.
Method 1: Add an Edit Post Link in WordPress using WPCode (Recommended)
For this method, add a code snippet by editing your theme’s functions.php file or using a code snippets plugin.
We’ll use the WPCode plugin instead of editing the functions.php file.
WPCode is free, easy to use, and won’t break your website if something goes wrong.
To start, install and activate the free WPCode plugin. You can follow a guide on how to install a WordPress plugin for step-by-step instructions.
The free version of WPCode has everything you need to add custom code to WordPress. For advanced features like scheduled snippets and conversion pixels, you can upgrade to WPCode Pro.
Once the plugin is activated, a new menu item labeled ‘Code Snippets’ will appear in your WordPress admin bar. Click on it to see a list of all the custom code snippets saved on your site. Since you just installed the plugin, your list will be empty.
Click the ‘Add New’ button to add your code snippet.
This will take you to the Add Snippet page. Here, you can choose a code snippet from the built-in library or add your own custom code.
For this tutorial, navigate to the ‘Add Your Custom Code (New Snippet)’ option and click on the ‘Use snippet’ button.
Name your snippet (we called ours ‘Add edit link to single posts’) and then copy and paste the following code in the ‘Code Preview’ box:
“`php
add_action(‘loop_start’, function () {
if (!is_singular() || !is_main_query()) {
return;
}
edit_post_link(__(‘{Edit}’));
}, 99);
“`
Don’t forget to choose ‘PHP Snippet’ as the code type from the dropdown menu on the right side of the screen.
This code snippet will add the edit link to both single posts and pages.
Scroll down to the Insertion section, ensure the Insert Method is ‘Auto Insert’ and the Location is ‘Run Everywhere.’
Toggle the switch from ‘Inactive’ to ‘Active’ and click the ‘Save Snippet’ button at the top of the page.
Now when you view a blog post, you should see an ‘Edit’ link at the top.
Method 2: Add an Edit Post Link by Manually Editing Your Theme Files
You can modify the individual theme files directly or create a child theme to override these theme files.
We recommend creating a child theme so you don’t lose the changes you made when you update your theme. For more details, see a beginner’s guide on how to create a WordPress child theme.
Whether you’re editing theme files directly or creating a child theme, you need to copy and paste the following code and add it to your theme’s single.php, post.php, index.php, or other content template files.
“`php
<?php edit_post_link(__(‘{Edit}’)); ?>
“`
This code adds a post edit link to your WordPress posts and pages. You can change the ‘{Edit}’ text to whatever you want the link to say.
For most themes, add this code inside the post loop directly after the post meta data.
For example, here’s how the code would look at the end of a theme’s post meta data:
“`php
By <?php the_author_posts_link(); ?> on <?php the_time(‘F jS, Y’); ?> in <?php the_category(‘, ‘); ?> <?php edit_post_link(__(‘{Edit}’), ”); ?>
“`
You can also add this code to any part of your theme where you want the edit post link to display. For example, you can add it to the bottom of your post content.
Once you’ve added the code and saved the file, upload it to your theme directory in your WordPress hosting account.
You can use an FTP client or the file manager option in your WordPress hosting control panel to do this.
If you haven’t used FTP before, check out a guide on how to use FTP to upload files to WordPress.
Now, when you’re logged into WordPress and viewing a post or page on the front end, you can simply click the ‘Edit’ link, and you’ll be taken to the post editor screen.