Duplicating a post or page on WordPress is easier than you think. Sometimes, you need to duplicate content on your WordPress website for normal tasks. By the end of reading this article, you will have more than sufficient ways to duplicate pages and posts on your WordPress website.

Most of the content for some pages like services, works, about, team, and other pages are similar and useful for each one of the pages. Even the formatting you have done on a page took 2 hours, and you don’t need to waste another two for the rest of the pages. Simply duplicate the pages as per your choice and enjoy editing the pages easily.

You will never need to copy and paste content if you know these methods to duplicate the content on your website. Check them all and choose wisely, whichever suits your case scenario. All of them are easy and come handy for WordPress websites.

#Method 1: Duplicate Page and Post on WordPress Site using Plugins

You can use different plugins on your WordPress website to duplicate the posts and pages. These are available for free on the WordPress library.

Plugins help the admin to duplicate the content without even coding a single line. Just a simple click on the post/page you like to copy & you are good to go.

#Plugin 1: Post Duplicator

Post Duplicator is another plugin that you can use to duplicate content on your website. It is an easy to use plugin which you can use to duplicate the content in simple steps. This creates the exact duplicate content of the page or post that you are trying to clone.

You can set the status of how you want the duplicated content on your website. All you have to do is first install the plugin as follows and go to the Toos > Post Duplicator and Check how you would like your duplicate content (Published or Draft and other values). To install, Follow:

  1. Open WordPress Dashboard.
  2. Click on Plugins > Add New Plugin.
  3. Search for Post Duplicator.
  4. Click on Install and Activate the Plugin.
  5. Head over to the page/post which you would like to clone.
  6. Under the title, you would see Duplicate Post/Page (accordingly).
  7. Click on the Duplicate button, and you will see a cloned content.

#Plugin 2: Duplicate Page and Post

This is another one of the most used plugins that you can try on your WordPress website. It can duplicate your content from the page or post you want to clone. However, It will not change anything, even the title or the style. You have to manually edit the content you wish to change.

Follow these steps to use this plugin:

  1. Open the WordPress dashboard of your website.
  2. Click on Plugins and then Add New Plugin.
  3. Search for Duplicate Page and Post.
  4. Install the Plugin and Click on Activate.
  5. Once activated, navigate to the page/post you would like to clone.
  6. Besides the other options to edit, you will find the Duplicate button.
  7. Click on Duplicate, and you will see the Cloned Post/Page you wished.

#Method 2: Duplicate Page and Post without Plugin

If you are someone who looks for manual tasks instead of believing in the 3rd-party plugins, This one is for you. You can simply add the duplication function in your WordPress website by adding this small code (pun intended ?).

You can continue using two methods (By WordPress Dashboard or File Manager). If you have access to the file manager from your cPanel, open the functions.php file. Otherwise, you can open it from your theme editor on the WordPress Dashboard.

After which, you need to add this code in the functions.php file and save the file.

Clear the cache, and you will see an option to duplicate posts without installing any additional plugin.

/*

* 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 );

 

You can even duplicate the pages with a similar code. All you have to do is change the last and replace it with:

add_filter( 'page_row_actions', 'rd_duplicate_page_link', 10, 2 );

This is how you could duplicate content on your website without any additional plugin. In most cases, plugins might face vulnerability attacks. Although, if you regularly update the plugins, they might not create a big problem for you.

Let’s Conclude

This was all about the methods you could use to duplicate pages and posts on your WordPress website. We strongly recommend taking a backup locally before proceeding with any of the above methods. If you have any doubts/queries, Share them with us in the comments.

Also, if you have any other method which is reliable and easier than these, share it with us. If you have used any of the above methods, Comment your experience on how you liked it. Feel free to share your experience with any of the plugins or methods we shared here.

Happy Duplicating!! ?

Previous ArticleNext Article

Leave a Reply

Your email address will not be published. Required fields are marked *