MEMORIAL DAY SALE: Get 50% Off On Our Annual Plan! Use Code "MEMORIAL" At Checkout

DOWNLOAD ALL NOW!

Owning a website becoming expensive?

No more! In our library, you will find the best premium WordPress plugins and themes for a fraction of the cost of the original prices. Browse Our Library

How to Duplicate WordPress Page or Blog Post With or Without a Plugin

How to Duplicate WordPress Page or Blog Post With or Without a Plugin

In this article, I’ll teach you how to duplicate a WordPress page or a blog post with or without a plugin.

Why Duplicate Pages or Posts in WordPress

There are many good reasons why to clone a WordPress page, post, or a custom post type such as download or product, and here are the most common ones:

  • Consistent design.
  • Save time.

Often, we want our web site’s pages to look the same. Consistent is a very important aspect of creating and designing a successful website.

If you designed a page that you’re satisfied with, it’s a waste to use it only once and start over with a new design on the next page. Cloning a page or a template will guarantee that the page or the post will look the same and also save you a lot of time.

Sometimes, designing a beautiful page takes a lot of time and thinking. There are many elements that need to come together to create an appealing design. Trust us, we know. Getting the desired results can take hours or even days and when we finally found it, we want to hold onto it.

That’s the best time to duplicate the page and reuse the design we created with some custom touches to fit the new page.

To save valuable time, knowing how to duplicate a page in WordPress will be very useful and beneficial to smooth our workflow.

In this article, you’ll learn how to duplicate or clone any kind of page, post, and custom post types such as EDD download or WooCommerce product. We will show you and walk you through three different methods, one with a plugin, and two without a plugin. You can choose your desired one based on your needs and requirements.

let’s start with the first way:

How to Duplicate Page or Post in WordPress

With a plugin

In this method, we are going to use a very good plugin called Duplicate Page. In fact, there are many good plugins that will do it but that is the easiest, fastest, with the least amount of settings to customize.

Navigate to Plugins -> Add New and search for Duplicate Page. Click Install Now and Activate.

Install Duplicate Page Plugin

Once activated, navigate to the desired post type screen (pages, posts, or custom post types).

In our example, we will duplicate a page. Thus, I’ll navigate to the page’s screen to see all my pages.

Navigate to all pages

Hover your mouse on the page that you would like to duplicate and click on the new Duplicate This option.

Once clicked, the page was duplicated and it has the same name.

Page was duplicated

The cloned page contains the same content as the original page and that means that the duplication process worked great. Edit the newly cloned page by giving it a different title and a slug and click publish.

Publish the new cloned page

As you may notice, duplicated pages or posts are set as drafts. Because the page is not fully ready to be published (you still need to change the title and some of the content) I recommend you to leave it that way. But, you do have the option to make it publish immediately after cloning by changing the plugin’s setup page.

To do that, navigate to Settings -> Duplicate Page. On this screen, you’ll have some basic simple settings that you can change base on your needs.

To make the duplicated pages published right ahead, change the Post Status to Publish and save the changes.

Duplicate Page Plugin Setting Page

Without a Plugin

Using a plugin is a simple and fast way to duplicate posts or pages but it’s not the only way. There is another great way to do it without a plugin but it will only work with post types that support the Gutenberg editor (not downloads or products).

Instead of navigating to the list of the available pages, enter into the page that you’d like to duplicate.

From inside the edit page, click on the three dots icon on the top right corner and choose Copy All Content.

Copy the content of a page

After coping with the content, we will need to create a page ourselves by clicking on Add New under the Pages tab.

Create a new page

All that has been left to do is to paste the content that you copied from the original page into the new-made page.

Paste the content that you copied

Once pasted, all the content and the Gutenberg blocks will appear exactly as you copied them. All you have left to do is to give the page a title and click publish.

Using a function

The last method that I would like to show you will mimic the use of a plugin. This time, we will use a function to achieve the same result without actually using any plugin.

To do that, we will need to have access to our functions.php file of our theme (child theme preferred).

You can access the functions.php file using an FTP client such as FileZilla or straight through your WordPress Dashboard.

To keep it simple, we will access our functions file from inside the WordPress dashboard.

Navigate to Appearance -> Theme Editor. On the list from the right, look for the functions.php file.

Look for the functions php file

Scroll to the bottom of the file and paste this code:

/*
 * 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 );
add_filter('page_row_actions', 'rd_duplicate_post_link', 10, 2);

After pasting the code, click on Update File.

Now, when navigating to the posts or pages screen, you’ll see the new option ‘Duplicate’ under each item of the list.

New duplicate option under page and blog posts

After clicking on Duplicate, you’ll be redirected to the new duplicated post or page to start editing it. When you have done, just publish the new page or post.

I’ve created a short video that will walk you through all of the methods quickly and easily. Feel free to watch it here:

Conclusion

Sometimes we will need to clone pages or post types of our WordPress website if we want to have a consistent design. In this article, we went through three different ways on how to do it. One way with a plugin and two other ways without a plugin.

If you have any questions or comments please let us know down below in the comment box.

Also, make sure to subscribe to our YouTube channel and like our page on Facebook.

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on email

PluginsForWP

PluginsForWP is a website specializing in redistributing WordPress plugins and themes with a variety of knowledge about WordPress, internet marketing, and blogging.

Leave a Reply