Do you need to duplicate a page or post in WordPress? Maybe you’re working on a new design for your website, and you want to duplicate an existing page to use as a template. Or perhaps you need to make a copy of an old post so that you can update the content. Whatever the reason, duplicating pages and posts in WordPress is accessible! This article will show you how to copy a page or post in WordPress using two methods.
Why Duplicate Pages and Posts?
You might want to duplicate a page or post in WordPress for several reasons. Here are a few:
You want to create a similar but slightly different page or post. For example, you may have an “About” page that you want to duplicate and use as the basis for an “About Us” page.
You want to use an existing piece of content as a template for a new one, and this is common when creating landing pages or other types of content that follow a similar format.
You want to create multiple pages or posts with similar content quickly. For example, you may want to duplicate a “Meet the Team” page and then edit the individual team member bios.
Whatever the reason, duplicating pages and posts can save you time when creating new content for your WordPress site.
Duplicate a Page Using WordPress Plugin
The first method we recommend is to use the Duplicate Page and Post WordPress plugin. It is a free plugin that allows you to duplicate pages and posts with just a few clicks. First, you must install and activate the Duplicate Page and Post plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.
Once the plugin is activated, go to Pages » All Pages and hover over the page you want to duplicate. You will see a new link labeled ‘Clone.’ Click on it to copy the page.
That will take you to a new page where you can edit the title and slug for your cloned page. The plugin will pre-fill these fields with the title and slug of the original page. You can leave these fields unchanged or edit them as you wish.
Scroll down to the bottom of the page and click on the ‘Clone Page’ button to save your changes.
Duplicate a Post Using WordPress Plugin
If you need to duplicate a post, the process is similar. Go to Posts » All Posts and hover over the post you want to repeat. You will see the ‘Clone’ link again. Click on it to duplicate the post.
That will take you to the editing screen for your new cloned post, where you can change the title and slug. Once you finish, scroll down and click the ‘Clone Post’ button to save your changes.
Duplicating a WordPress Page or Post Without a Plugin
If you don’t want to install a plugin, you can duplicate a wordpress page or post using the built-in editor. However, this method requires more steps and is not as beginner-friendly.
First, you need to create a new page or post. For this example, we will duplicate an existing page. So go ahead and create a new page.
Add a title on the editing screen and click on the ‘Copy content from another page’ link under the page editor.
A modal window will appear where you need to select the page that you want to copy. Once you set the page, click the ‘Copy’ button.
It will copy all the content from the original page into your new page. You can now edit the title and slug for your new page and click on the ‘Publish’ button to save your changes.
Use The Code In functions.php To Enable Cloning
If you don’t want to install a plugin or duplicate a page manually, you can add a simple code snippet to your WordPress site. This method requires you to edit your WordPress files, so we only recommend it for advanced users.
First, you must connect to your WordPress site using an FTP client. Once connected, go
to the /wp-content/themes/your-theme/ folder.
Inside your theme folder, you need to edit the functions.php file. If you don’t see the functions.php file, then you can create one by adding this line of code to the top of your theme’s header.php file:
<?php get_template_part( ‘functions’ ); ?>.
You can now add the following code snippet to your functions.php file. This code enables to post and page cloning for WordPress users with the ‘edit_posts’ capability:
function duplicate_post() {
if ( current_user_can( ‘edit_posts’ ) ) {
add_action( ‘admin_action_duplicate_post’, ‘ duplicate_post_create_duplicates’ );
}
}
add_action( ‘init’, ‘ duplicate_post’ );
function duplicate_post_create_duplicates() {
if ( ! ( isset( $_GET[‘post’]) || isset( $_POST[‘post’]) || ( isset($_REQUEST[‘action’]) && ‘duplicate_post’ == $_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 the 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->ID, // post parent id is same as original post id
‘post_password’ => $post->post_password,
‘post_status’ => ‘draft’, // you can change this to publish if you want
‘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 = wp_insert_post( $args );
/*
* 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 == ‘_wpdmsp_ duplicate post’ ) continue;
$meta_value = addslashes($meta_info->meta_value);
$sql_query .= “SELECT {$new_post}, ‘$meta_key’, ‘$meta_value’ UNION ALL “;
}
$sql_query = substr($sql_query, 0, -11);
$wpdb->query($sql_query);
}
/*
* finally, duplicate all post taxonomies/terms
*/
$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 = get_the_terms( $post_id, $taxonomy );
$post_terms_count = sizeof($post_terms);
for ($i=0;$i
duplicate the post and its content.
*/
duplicate: function duplicate() {
// your code here…
}
})();
?>
FAQs
Why would I want to duplicate a page or post in WordPress?
There are a few reasons you might want to duplicate a page or post in wordpress:
- You may want to create a similar but slightly different page or post. For example, you may want to duplicate a blog post and make some changes to it before publishing.
- You may want to use an existing piece of content as a template for a new one. It is beneficial if you frequently create similar content.
- You may want to duplicate a page or post as a staging draft before making live changes to the original page or post.
What’s the difference between duplicating and copying a page or post in WordPress?
A duplicate copy is created when you duplicate a page or post in WordPress. The identical copy is an exact original duplicate and has a unique URL. You can then edit the duplicate copy without affecting the original.
When you copy a page or post in WordPress, the copied content is added to the WordPress editor. You can then change the copied content and publish it as a new page or post. Copying a page or post does not create a duplicate copy with its URL.
Conclusion
Bloggers and site owners often duplicate pages or posts for many reasons. Maybe you want to create a similar but slightly different page or post. Or, you may want to use an existing piece of content as a template for a new one. Whatever the reason, duplicating pages and posts in WordPress is easy to do.
Do you have any questions about duplicating pages and posts in WordPress? Let us know in the comments section below! If you found this article helpful, please share it with your friends. Thank you for reading!