SPECIAL OFFER Get 30% OFF on All Qode Plugins Discount code: WOOCOMMERCE30 SPECIAL OFFER Get 30% OFF on All Qode Plugins Discount code: WOOCOMMERCE30 SPECIAL OFFER Get 30% OFF on All Qode Plugins Discount code: WOOCOMMERCE30
SPECIAL OFFER Get 30% OFF on All Qode Plugins Discount code: WOOCOMMERCE30 SPECIAL OFFER Get 30% OFF on All Qode Plugins Discount code: WOOCOMMERCE30 SPECIAL OFFER Get 30% OFF on All Qode Plugins Discount code: WOOCOMMERCE30
BACK TO TOP

How to Duplicate Your WordPress Pages or Posts

How to Duplicate Your WordPress Pages or Posts

If you can’t think of a single reason why anyone would need to duplicate their pages or posts in WordPress, you probably never had to redesign your site. If you did, you’d know just how useful duplicating pages or posts can be.

In this article, we’re going to show you how to duplicate a page in WordPress, the benefits of creating duplicate pages or posts and teach you three ways to do it: manually, using a plugin and using code.

Here’s what we’ll discuss:

Why and When to Duplicate WordPress Pages or Posts?

One of the most common situations in which WordPress users can benefit from duplicate pages or posts is when they want to revamp, refresh or overhaul an existing page, but they don’t want to lose all its content. The same goes for posts, of course. It’s an essential technique in repurposing old content, and it’s much better than the simple copy/paste.

“What’s wrong with copying and pasting the content in a new draft to use it again after you make the changes?” you might ask. Well, of course, that would work but it would be pretty time-consuming, for one thing.

Also, and more importantly, it might affect all your previous SEO efforts, and, consequently, damage your page rank. This is because, when you simply copy the content and paste it on a page that you have redesigned, everything you’ve done SEO-wise, as well as your featured image, page templates and other related data, would be lost.

Also, duplicate pages are useful for situations when you just want to tweak a few things in your page design, for example, and compare it with the old version to see which one works better. This is particularly handy for when you’re redesigning your website and need to see how your content will fit your new design elements.

As you can see, there are many situations in which creating a clone or a duplicate of your page or post comes in handy.

How to Duplicate a WordPress Page Manually?

This will depend on the page builder you’re using. For Elementor users, there isn’t a single Duplicate feature as such, but what you can do instead is save your existing page as a template and then use it to create a new one that represents an exact duplicate.

In the page you want to duplicate, navigate down to the bottom left of the screen and click on the arrow to open the menu, where you will select Save as Template.

Save as Template Elementor

This will open a dialog box where you can give your template a name. It will be saved in the Elementor templates folder from which you can always access it and reuse it.

Elementor templates folder

Now go ahead and create a new Elementor page. Give it a title and then click ont he folder icon to access your saved template.

Access your saved template

Navigate to the My Templates section, find the template you need and click on Insert.

My Templates section

And just like that, all the content, design and page settings will be recreated right there in your new page.

Now, as for Gutenberg, the process is similar, except you will be copying blocks. Access the page you want to duplicate and in the upper right corner of the screen click on the three dots. In the menu that opens, select Copy all blocks.

Copy all blocks

Now create a new page, give it a title and simply right-click and select Paste or press Ctrl+V and your copied blocks (design and content) will be pasted into the new page, which will be an exact duplicate of the one you copied.

Now, this is a method that works best for occasionally copying single pages or posts. It may not suffice for bulk actions and for more streamlined duplicating processes, which is why it’s worth considering other solutions.

Duplicating Pages or Posts Using a Plugin

As is so often the case with WordPress, the most useful solutions come in the form of our little friends, the plugins. While there are several excellent plugins for duplicate pages and posts on the market, we can’t possibly feature them all, so we’re going to talk about the most popular one – Yoast Duplicate Post.

Yoast Duplicate Post

This is a neat, simple and functional plugin with over three million active installations that you can download and use for free.

Once you have installed and activated the plugin, go to your posts or pages, and you’ll notice some new options appear as you hover above the post you want to duplicate. There will be two options: Clone and New Draft.

Post options Clone and New Draft

The Clone option creates the exact duplicate of the post you want to edit or change. The duplicate will appear on top of the list of posts and, clicking on it, you will be able to edit it the usual way.

The Clone option

New Draft, on the other hand, creates a clone of the page and then opens the page/post editor right away. Once you’ve made all the necessary changes to the post, click on Publish and review it live.

New Draft option

And that’s really all there is to it. Once you no longer need the clones, you can delete them quickly by clicking on the Trash link that reveals underneath the post upon hover.

Delete post

Duplicating Pages or Posts Using Code

While plugins are certainly of tremendous help in many situations, sometimes we want to get our hands dirty and get things done by ourselves, without resorting to a plugin. This may be because we want to test our knowledge and expertise or show ourselves that we can do it on our own. But more often it’s because we already have dozens and dozens of plugins installed and we feel that installing a new one would weigh the whole thing down too much.

Either way, it is possible to duplicate a page or a post just using code. One GitHub user came up with a neat function for creating duplicate posts or pages that you simply need to copy to your functions.php 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 ad 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( 'post_row_actions', 'rd_duplicate_post_link', 10, 2 );
to join this conversation on GitHub. Already have an account? Sign in to comment

You can do it directly on your server using an FTP client of your choice, but we suggest you simply use the WordPress file editor.

Note here that this code is written for duplicating WordPress posts. If you want to duplicate pages as well, you need to change the last line in the snippet so that, instead of ‘post_raw_actions’ it says ‘page_raw_actions’.

After you have entered the code in your functions.php file, go to your dashboard where your pages and posts are listed (All Posts or All Pages). If everything worked fine, there will be a new option available underneath each of the posts or pages, saying simply Duplicate. Clicking on it will create a clone of that particular page or post, just as it would if you were using a plugin.

New Themes
Congrats
Congrats

Event Planner & Party Decoration WordPress Theme

Zentrum
Zentrum

Property & Apartment Showcase WordPress Theme

HighRev
HighRev

Car & Auto Parts WooCommerce Theme

Final Thoughts

As you can see, creating duplicate WordPress pages or posts is actually a piece of cake, whether you’re doing it manually, using a plugin or opting for code instead. We are sure you’ll find this option more than convenient in many situations.

Now that you know how to duplicate a page in WordPress, just remember to clean up the unused duplicate posts once in a while – clutter is never a good thing for a website. Also, if you intend to use code to duplicate posts, make sure your website is backed up, as it should be whenever you’re editing WordPress files.

Post your comment

Comments0