How to Duplicate WordPress Posts and Pages

Cloning or Duplicating a post or a page is a common trend. Reasons are many but the common scenario includes formatting a current page. For keeping the data intact for future reference. For this, you can copy/paste the content and save them as a draft but that is not a legitimate method to do so. Because it will not get SEO Optimization, page templates, images, and allied data. Using a template for creating a standard post is a valid and easiest method. There are endless methods for cloning a page or posts for WordPress. This tutorial will teach you various ways to duplicate a page and posts for WordPress with a single click. Simplest and easiest options are listed below; you can choose one as per your preference.

Also Read: Best Plagiarism Checkers Tools of 2019

The Best Ways to Duplicate Pages and Posts for WordPress:

Without much ado, let’s get started!

When do you need to Copy a Page?

• When you desire others to follow the pre-configured format for page creation.

• The same structure can be used without wasting time.

• This will help in saving the page layout and just linking images for further orientation.

Basic Requirement:

You will need to fulfill this basic requirement before you begin with the guide:

Access to WordPress Admin Panel

**To Be Noted: Before you begin with the formatting of your WordPress files always create a backup for safety.

1st Method: Duplicating WordPress Posts and Pages and Posts without Plugins:

By Coding, you can safely duplicate your WordPress posts and pages. However, this needs little computer knowledge. So if you are amongst those who like programming, this is spot on for you. Even if you are not aware of it but desire to get it done this way, we have sorted this out for you. Check out the snippet provided below:

/*

* Function for post duplication. Dups appear as drafts. The 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 );

This snippet only works for WordPress posts, to get WordPress pages cloned add following:

add_filter(‘page_row_actions’, ‘rd_duplicate_post_link’, 10, 2);

Paste the given code to functions.php file or just use a File manager, FTP Client. You can even use WordPress file editor for task completion. Now you will see a duplicate button while navigating through posts or pages. Just press this button to create a copy and save it in your drafts.

2nd Method: Duplicating WordPress Posts and Pages via Duplicate Posts Plugin:

The easiest way to duplicate a page is through Duplicate Post Plugin. By choosing this method you can customize your page and save a copy. This helps you to add a suffix or prefix copy and also restrict various functionalities.

Read: How to Install a WordPress Plugin – Step by Step for Beginners

Follow the given method:

• Installing and activating the plugin

• Tap on Pages and go to All Pages icon

• Click on the post or page you wish to clone and you will see to options in front of you: Clone and New Draft.

• Click Clone and save the post.

• Or you can click on New Draft and save the copy for later editing in the post editor.

3rd Method: Cloning WordPress Posts and Pages via Post Duplicator:

If the above methods didn’t work for you, try this Post Duplicator. This plugin creates a carbon copy of your posts and pages. This will also help you in retaining customize options. Begin with:

• Install and activate Post Duplicator

• Go through the page or post and click on Duplicate icon.

• Duplicating is done.

4th Method: Using Duplicate Page and Post Plugin for WordPress Posts and Pages Duplication:

Yet another plugin for instantly cloning pages and posts. The content including title and styling all remains intact while replicating.

Follow the mentioned steps to use this plugin:

• Install and activate Duplicate Page and Post Plugin

• Go to Pages> All Pages (For duplicating pages) Else Posts> All Posts for WordPress post.

• Drift to the posts and click on Clone Me.

• A cloned copy will pop up in your screen. Save it as a draft.

Outlook:

The plugins mentioned are boon. If you were unaware of this before, not to worry as you are now a master. Hope this editorial has helped you in getting your job done. Well if you still have some queries related to it. You can comment us in the provided section.

We will be glad to know your suggestions and tips.

Leave a Reply