Duplicating a WordPress page is much more complicated than simply copying the page’s content. To truly duplicate the page, you’ll need to copy the template of the page, images, SEO data, CSS, PHP codes, and more. Duplication can only be achieved by manipulating the code within the page or the code governing the website’s functions.
Thankfully, there are simple ways to duplicate pages in WordPress that any user can deploy, and you don’t need any coding knowledge for these. Furthermore, if you want more control over the process, you can manually create a process for cloning pages.
In this article, we’ll look at the 3 methods to duplicate a page in WordPress, describing each process step-by-step with screenshots. For the more complicated method, I’ll also provide an explanation of the code involved so that you can understand precisely what you’re doing.
How Can I Duplicate A Page In WordPress?
These are the 3 ways you can duplicate a page in WordPress.
Method 1: Copying The HTML Code From The Page
The simplest method of duplicating a page in WordPress is to copy the HTML code directly from a page and then paste it onto a blank one. Here’s how you can do it.
- From your Dashboard, select the Pages option from the menu on the left.
- Once you’re in the Pages section, click on any page that you want to duplicate. For the sake of this demonstration, I’ll be duplicating the “About” page.
- Once you’ve accessed the target page, click the Options button on the top left corner of your screen. It’s represented with 3 vertical dots.
- From here, go to the EDITOR section, and select the Code editor option. This will toggle the HTML view of the page. Alternatively, press the keys Ctrl, Shift, Alt, and M together and toggle the HTML view.
- Once you’re in this mode, the page will display the heading and the HTML code of the content.
- From here, click on the code, and press Ctrl and A together to select everything. Press Ctrl and C to copy the code. Then click on the upper right corner of your screen to go back to the Pages section.
- Once you’re back in the Pages section, look at the menu on the left again. Under Pages, select the Add New option.
- The new page should already be in the code editor mode. If not, then follow options 3 and 4 to toggle it again.
- Paste the code from the previous page into the text box. Give the new page a name in the Add Title box.
- You can now save the page as a draft or publish it immediately. Both options are available on the upper left section of your screen.
- If you want to check if your page has been duplicated properly or not, simply click on the exit code editor option on the upper left section of your screen. This will toggle the visual editor mode, and you can see if everything’s here.
- Alternatively, you can choose the Preview option, which will provide you with a dropdown menu. You can choose which device preview you’d like to see, then select Preview in the new tab. The page will be saved as a draft automatically, and you can check what it looks like.
And it can become quite tedious to copy the content and create a new page repeatedly. For frequent and proper duplication, it’s best to try the following methods.
Method 2: Using A Plugin To Copy The Page
If you have to duplicate WordPress pages more frequently and want it done at the push of a button, a good choice is to use a plugin. Plugins are easy to install, simple to manage, and mostly work with a single click. There are a multitude of options available that allow duplication of pages and articles, but these are the best ones.
- Yoast Duplicate Post by Enrico Battocchi & Team Yoast.
- Duplicate Page by mndpsingh287.
- Duplicate Page and Post by Arjun Thakur.
- Post Duplicator by Metaphor Creations.
All of these plugins have similar installation and usage, so I will be demonstrating how to install and use these plugins by using “Yoast Duplicate Post by Enrico Battocchi & Team Yoast”.
To install the plugin, follow these steps.
- From your Dashboard, hover your cursor over Plugins in the menu on the right middle section of your screen. A dropdown menu will appear with the Add new option at the bottom.
- Click on Add new, and you’ll be taken to the WordPress Plugin Directory. Select the search box on the right section of the screen, and type in “Yoast Duplicate Post.” Afterward, click on the Search button adjacent to the bar.
- After clicking on Search, the “Yoast Duplicate Post” plugin will appear as the 1st search result on the left of the screen. Click on the Install button to install the plugin.
- Once it’s done installing, the same button will display the Activate option. Click on it once more to enable the plugin.
- Once it’s enabled, the plugin will disappear from the page.
To use the plugin, go through these steps.
- Click on the Pages section in the menu on the right of your screen from the Dashboard.
- Once in the Pages section, hover over the article you want to duplicate. This will reveal a number of options right underneath the title of the page. From here, select the Clone option.
- Clicking this option will create a draft with the same title, but “Customization Draft” will be written beside it.
- Plugins are the most straightforward and most convenient option to frequently duplicate pages.
Method 3: Using PHP to clone the page
You can duplicate a WordPress page by inserting PHP code in your “functions.php” file. This method allows you to clone articles/pages you want and save them as drafts. It’s quite risky compared to the 2 methods above, so it’s best to create a backup of your file.
To find and access your “functions.php” file, follow these steps.
- From your Dashboard, hover your mouse over the Appearance option from the menu on the right.
- You’ll find a dropdown menu pop-up from Appearance, which will contain the Theme Editor option at the very bottom. Select this option, and you’ll be taken to the Edit Themes section.
- In the Edit Themes section, look at the Theme Files menu on the right. From here, click on the “functions.php” file.
- Once you’re in the “functions.php” file, you should create a backup of the code written here. Any mistake can easily ruin your website, and restoring from a backup can save you hours of headaches. You can simply copy the code here by copying everything here and pasting it into a Txt file through Notepad on your computer. If you need to restore the file, replace the code in “functions.php” with the code from the Txt file.
- In the “functions.php” file, copy and paste the code I’m mentioning below at the end of the file.
/*
* Function for post duplication. Dups appear as drafts. User is redirected to the edit screen
*/
function rd_duplicate_post_as_draft(){
global $wpdb;
if (! ( isset( $_GET[‘post’]) || isset( $_POST[‘post’]) || ( isset($_REQUEST[‘action’]) && ‘rd_duplicate_post_as_draft’ == $_REQUEST[‘action’] ) ) ) {
wp_die(‘No post to duplicate has been supplied!’);
}
/*
* Nonce verification
*/
if ( !isset( $_GET[‘duplicate_nonce’] ) || !wp_verify_nonce( $_GET[‘duplicate_nonce’], basename( __FILE__ ) ) )
return;
/*
* get the original post id
*/
$post_id = (isset($_GET[‘post’]) ? absint( $_GET[‘post’] ) : absint( $_POST[‘post’] ) );
/*
* and all the original post data then
*/
$post = get_post( $post_id );
/*
* if you don’t want current user to be the new post author,
* then change next couple of lines to this: $new_post_author = $post->post_author;
*/
$current_user = wp_get_current_user();
$new_post_author = $current_user->ID;
/*
* if post data exists, create the post duplicate
*/
if (isset( $post ) && $post != null) {
/*
* new post data array
*/
$args = array(
‘comment_status’ => $post->comment_status,
‘ping_status’ => $post->ping_status,
‘post_author’ => $new_post_author,
‘post_content’ => $post->post_content,
‘post_excerpt’ => $post->post_excerpt,
‘post_name’ => $post->post_name,
‘post_parent’ => $post->post_parent,
‘post_password’ => $post->post_password,
‘post_status’ => ‘draft’,
‘post_title’ => $post->post_title,
‘post_type’ => $post->post_type,
‘to_ping’ => $post->to_ping,
‘menu_order’ => $post->menu_order
);
/*
* insert the post by wp_insert_post() function
*/
$new_post_id = wp_insert_post( $args );
/*
* get all current post terms and set them to the new post draft
*/
$taxonomies = get_object_taxonomies($post->post_type); // returns array of taxonomy names for post type, ex array(“category”, “post_tag”);
foreach ($taxonomies as $taxonomy) {
$post_terms = wp_get_object_terms($post_id, $taxonomy, array(‘fields’ => ‘slugs’));
wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false);
}
/*
* duplicate all post meta just in two SQL queries
*/
$post_meta_infos = $wpdb->get_results(“SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id”);
if (count($post_meta_infos)!=0) {
$sql_query = “INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) “;
foreach ($post_meta_infos as $meta_info) {
$meta_key = $meta_info->meta_key;
if( $meta_key == ‘_wp_old_slug’ ) continue;
$meta_value = addslashes($meta_info->meta_value);
$sql_query_sel[]= “SELECT $new_post_id, ‘$meta_key’, ‘$meta_value'”;
}
$sql_query.= implode(” UNION ALL “, $sql_query_sel);
$wpdb->query($sql_query);
}
/*
* finally, redirect to the edit post screen for the new draft
*/
wp_redirect( admin_url( ‘post.php?action=edit&post=’ . $new_post_id ) );
exit;
} else {
wp_die(‘Post creation failed, could not find original post: ‘ . $post_id);
}
}
add_action( ‘admin_action_rd_duplicate_post_as_draft’, ‘rd_duplicate_post_as_draft’ );
/*
* Add the duplicate link to action list for post_row_actions
*/
function rd_duplicate_post_link( $actions, $post ) {
if (current_user_can(‘edit_posts’)) {
$actions[‘duplicate’] = ‘<a href=”‘ . wp_nonce_url(‘admin.php?action=rd_duplicate_post_as_draft&post=’ . $post->ID, basename(__FILE__), ‘duplicate_nonce’ ) . ‘” title=”Duplicate this item” rel=”permalink”>Duplicate</a>’;
}
return $actions;
}
add_filter(‘page_row_actions’, ‘rd_duplicate_post_link’, 10, 2);Credit: https://wpengine.com/resources/how-to-duplicate-page-wordpress/
This bit of code is set to allow cloning pages, but if you want to clone articles instead you can swap the last line with the line below.
add_filter( ‘post_row_actions’, ‘rd_duplicate_post_link’, 10, 2 );
- Once you’ve pasted the code, click on the Update File button, and the “functions.php” file will be modified.
- Afterward, you can find a Duplicate button by hovering over any page in the Pages section.
As I’ve mentioned before, inserting code that you don’t understand can easily wreck your website and leave you clueless as to how you can fix it. It’s best to not approach this method without proper knowledge of PHP.
For those who don’t understand PHP code, I’ll briefly explain the operations of the code mentioned here.
/*
* Function for post duplication. Dups appear as drafts. User is redirected to the edit screen
*/
This simple comment describes what this code is supposed to do. There are many other comments like this skittered throughout the codes.
function rd_duplicate_post_as_draft(){
This is the function that commands posts to be duplicated as drafts.
global $wpdb;
The $wpdb variable allows the user to access the WordPress database.
if (! ( isset( $_GET[‘post’]) || isset( $_POST[‘post’]) || ( isset($_REQUEST[‘action’]) && ‘rd_duplicate_post_as_draft’ == $_REQUEST[‘action’] ) ) ) {
wp_die(‘No post to duplicate has been supplied!’);
This line checks whether a post ID has been delivered through $_GET, $_POST or the $_REQUEST variables. If there is no post found, then it displays an error message with the wp_die() function.
/*
* Nonce verification
*/
if ( !isset( $_GET[‘duplicate_nonce’] ) || !wp_verify_nonce( $_GET[‘duplicate_nonce’], basename( __FILE__ ) ) )
return;
The duplicate_nonce is a security nonce searching function that looks for input from $_GET and checks validity through wp_verify_nonce(). If nothing is found, it stops execution via the return function.
/*
* get the original post id
*/
$post_id = (isset($_GET[‘post’]) ? absint( $_GET[‘post’] ) : absint( $_POST[‘post’] ) );
The $post_id function looks for the post parameter from the $_GET or $_POST functions, and the absint() function cleans the input and converts it into an integer.
/*
* and all the original post data then
*/
$post = get_post( $post_id );
The get_post() function fetches data relevant to the post ID stored in $post_id.
/*
* if you don’t want current user to be the new post author,
* then change next couple of lines to this: $new_post_author = $post->post_author;
*/
$current_user = wp_get_current_user();
$new_post_author = $current_user->ID;
The wp_get_current_user() function fetches the current user’s ID and sets it as the $new_post_author variable’s value. This allows the user to duplicate the post and become the draft’s author.
/*
* if post data exists, create the post duplicate
*/
if (isset( $post ) && $post != null) {
This line verifies whether the $post variable exists and is not invalid.
*/
$args = array(
…
);
/*
*/$new_post_id = wp_insert_post( $args );
/*
The $args function creates an array that fetches the post’s name, password, title set on the header, type, menu order, and more. It also sets the post’s status as a draft. $new_post_id sets the post terms to the drafted copy.
*/
$taxonomies = get_object_taxonomies($post->post_type); // returns array of taxonomy names for post type, ex array(“category”, “post_tag”);
…
$wpdb->query($sql_query);
}
/*
These lines fetch the extra metadata and place it into the new document. $taxonomies, $post_meta_infos, and similar functions fetch the metadata needed.
wp_redirect( admin_url( ‘post.php?action=edit&post=’ . $new_post_id ) );
exit;
} else {
wp_die(‘Post creation failed, could not find original post: ‘ . $post_id);
}
}
add_action( ‘admin_action_rd_duplicate_post_as_draft’, ‘rd_duplicate_post_as_draft’ );
These lines fetch the admin URL and attach it to the new post and complete the drafting process. Also, the user is programmed to arrive at the edit screen afterward.
function rd_duplicate_post_link( $actions, $post ) {
if (current_user_can(‘edit_posts’)) {
$actions[‘duplicate’] = ‘<a href=”‘ . wp_nonce_url(‘admin.php?action=rd_duplicate_post_as_draft&post=’ . $post->ID, basename(__FILE__), ‘duplicate_nonce’ ) . ‘” title=”Duplicate this item” rel=”permalink”>Duplicate</a>’;
}
return $actions;
}
add_filter(‘page_row_actions’, ‘rd_duplicate_post_link’, 10, 2);
Finally, these lines generate the duplicate draft’s link and add it to the action row, completing the duplication process.
Best Practices for Duplicating WordPress Pages
Now that you understand what methods are available for duplicating WordPress pages, here are some best practices to keep in mind.
- Backup before duplicating. Before making any significant changes, it’s always a good idea to create a backup of your website. This ensures that you can easily restore your site if something goes wrong during or after the duplication process.
- Update permalinks. If the duplicated page is going to coexist with the original, make sure to update the permalink structure to avoid conflicts. WordPress will automatically append “-2” to the duplicated page’s URL, but you may want to customize it for clarity.
- Review SEO settings. Before you take a duplicated page live, ensure that it has unique metadata, including a title, description and focus keyword. Pages with identical metadata can lead to SEO penalties and a drop in rankings.
- Review shortcodes and widgets. If your original page includes shortcodes or widgets, double-check that they function correctly on the duplicated page. Sometimes, certain elements may not work as expected after duplication.
- Remove unnecessary elements. If the duplication process brought over unnecessary elements (extra widgets, plugins, etc.), remove them to keep the duplicated page clean and optimized.
- Test responsiveness. Ensure that the duplicated page is responsive and displays correctly on various devices. Check the layout on desktops, tablets, and mobile devices.
- Clear your cache. If you use caching plugins, clear the cache after duplicating a page to ensure that visitors see the updated content.
- Update menus. If you want your new page to appear in any of your menus, don’t forget to update them accordingly.
By following these best practices, you can minimize potential issues and ensure a smooth duplication process in WordPress. Always test the duplicated page thoroughly before making it live on your site.
Conclusion
Using a plugin is the most dependable way to duplicate a WordPress page. Plugins are easily installed and take a single press to get the job done in most cases. Removing them is also quite simple, and it doesn’t cripple your website in any way.
If you’re looking for information on creating new pages and posts in WordPress instead, you can check out our detailed guide on this topic on our website.
If you’re still confused, or want expert assistance in managing your website, you can check out our WordPress Support & Maintenance Plans. We offer a free Zoom call with our specialists to evaluate your needs, and offer appropriate levels of support.