Making updates to a page or post can be intimidating once your WordPress site is live. Without a way to test your changes first, you run the risk of disrupting the user experience for your visitors. This risk is magnified when you are managing a site for a client.

A WordPress duplicate page could be the solution to your problems. By creating a duplicate, you retain the page’s style and any additional code that you know works correctly on the live site. This enables you to make your change and push it live when you are ready, with minimal disruption for your visitors.

In this article, we’ll discuss how to duplicate a page in WordPress. We’ll start with a clean code solution, then recommend some plugins that can help you create a WordPress duplicate page. Let’s begin!

Why You Might Want to Create a WordPress Duplicate Page or Post

There are many reasons you may want to duplicate or clone a page or post in WordPress. For instance, if you have a live site and want to make a change to your content, having a copy enables you to test your update before making it publicly visible.

There are plenty of scenarios in which a duplicate WordPress page may come in handy. These are just a few examples:

  • You want to retain the layout and format while only updating the content. This comes in handy if you have a landing page and you would like to make it a template for future ones.
  • You want to make a change and test it, but an author is working on the original. If you are working in an environment with multiple authors, you can avoid overwriting each others’ work.
  • You can use a cloned page for your client to sign off on before moving it live. If you are designing or developing for a client, a duplicate gives a way for them to approve the changes before implementing them.

Whatever your reasons, having a stopgap between making changes and publishing them gives you needed flexibility. It also provides you with a way to maintain consistency throughout your site, while avoiding issues with user experience for the site’s readers and your internal team. Once you are confident in the changes you’d like to make, you can apply them to the live version of your page or post without a hitch.

How to Manually Duplicate Pages and Posts

A screenshot from GitHubGist.

You can find code for duplicating pages and posts on GitHubGist.

While there are several plugin options for duplicating pages and posts in WordPress, you may be more interested in using a clean code solution. The advantage of making a manual change is that you won’t have to rely on plugin updates or support, especially as the plugin ages and your site evolves.

Before we get started, it is extremely important that you perform a site backup. Since you will be working with the functions.php file, any changes you make can have an impact on your site. You will want to make sure you can restore it in case something goes wrong.

To access the functions.php file using the WordPress editor, go to your dashboard and select Appearance. You should see Templates listed to the right of the editing window. Click on Theme Functions (functions.php):

The functions.php file in WordPress.

Once there, you will need to add the following code to the file in order to create duplicate posts:

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

If your edit is successful, when you next look at the post summary you will see a Duplicate link next to View:

An option to duplicate a page or post in WordPress

With this code, you are telling WordPress that you want the ability to duplicate the various parts of what goes into a post (categories, titles, comments, etc), and to add a link to the All Posts screen to enable this.

You only need one more line of code to do the same thing for Pages. Replace the last line of the above code snippet with this one:

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

Once you’ve saved the edited file and refreshed, you should see a new link in both the All Posts and Pages screens of your dashboard.

This method enables you to manipulate whatever theme you are using through the WordPress core. If you are not comfortable with code, however, don’t worry. There are plugin options that you can use instead.

3 Plugins to Help You Create a WordPress Duplicate Page or Post

If you aren’t very comfortable working with code, you may want an alternative solution. The beauty of WordPress is that there are usually multiple ways to accomplish the same task. When it comes to creating a duplicate WordPress page, there are several plugins you can use to accomplish your goal. We’ll focus on three that may be the most beneficial to you.

1. Duplicate Page and Post

The Duplicate Page and Post plugin

Duplicate Page and Post lets you create a WordPress duplicate page or post through the Bulk Actions menu of your dashboard pages. It is also engineered to seamlessly work with most of the plugins you are probably already using (such as Yoast, Divi Builder, and WooCommerce).

Key Features:

  • You can use the Bulk Actions menu to apply changes to pages and posts.
  • It’s compatible with All In One SEO Pack, WooCommerce, Divi Builder, and Yoast SEO.
  • You can duplicate items directly from the Edit Post/Page view screen.

To use this tool, go to the Plugins area of your admin dashboard. From there, choose Add New and search for the plugin, then install and activate it. Once activated, you will see a new link in the Bulk Actions menu for your posts and pages.

2. Duplicator

The Duplicator plugin.

Duplicator enables you to clone, migrate, move, or copy your site from one location to another. While it markets itself as a simple backup tool, it is actually extremely powerful. You can essentially use it to create a staging area for your site. You can make changes, test them, and (once you are sure they are ready) deploy them on your live site with no downtime. The tool bundles everything on your site, including themes, plugins, all of your page and post content, and your database files.

Key Features:

  • Use it to clone or migrate a WordPress site with no downtime.
  • You can create a local site or a site on any domain you need.
  • You don’t have to worry about using any scripts, because it even clones your database files.
  • The Pro version enables you to create backups on a schedule, or send them to Dropbox.

Once Duplicator is installed and activated, you will see a new navigation option for it in your dashboard. When you select it, you will see a message that you haven’t created any packages. This is where you can choose Create New and follow the steps of the creation wizard to clone your site and move it to a new location.

3. WP Staging

WP-Staging

Much like Duplicator, WP Staging enables you to create a staging or development area for your live site to avoid disruption for your end users. The difference is that this plugin creates a clone of your site within a subfolder of your main WordPress installation. It also copies your themes, plugins, and databases, so you can test anything before deploying it live for the public to see. The best part is that all of your links will be automatically corrected for you, so you don’t have to do any extra testing before you start staging.

Key Features:

  • Migrate your site to a staging area without having to do any configuration.
  • It’s amazingly fast, and you can migrate a site within a few minutes (or in some cases, seconds).
  • It secures your staging area so that only admins can access it.
  • The admin bar shows whether you are making changes in staging or on your live version, to avoid confusion.

After installing and activating the plugin, go to your Settings and select Staging. From there it is simply a matter of naming your staging area and letting the wizard clone the site to its new location.

Which Duplication Plugin Should You Use?

The practical difference between each of these plugins lies in how you plan to duplicate a WordPress page. For example, the Duplicate Page and Post plugin enables you to work on a single page or post within your current WordPress setup. On the other hand, the Duplicator and WP Staging plugins let you clone your full site and build out a complete staging area. Duplicator enables you to save your site in any location you choose, whether on your server, a local machine, or a new hosting provider. WP Staging clones your site to a subfolder on your main WordPress installation.

Which plugin you choose to create a WordPress duplicate page or post should be based on your goals and preferred work flow. However, we always recommend that you have a way to back up your full site. So, if you don’t have a current backup utility in place, Duplicator may be your best option to cover both your backups and your staging area. If you prefer working in a development environment that matches your current WordPress installation, however, WP Staging is a solid choice.

Conclusion

Managing a live site means you have to plan for even the smallest changes. By creating a WordPress duplicate page or post, you can test any updates or customizations in a safe environment, before they go live. If you work with clients, you can also give them the ability to test any changes you make before they approve them for launch.

In this piece, we discussed how to duplicate a page in WordPress in two different ways. First, we explained how to edit the functions.php file, and then we introduced you to a few useful plugins, namely:

  1. Duplicator: A multi-purpose tool that handles backups, migrations, duplication, and more.
  2. Duplicate Page and Post: A dedicated solution that is simple to use.
  3. WP Staging: A plugin that creates a cloned version of your site, which you can use for development and testing.

Do you have questions about creating a WordPress duplicate page or post? Let us know in the comments section below!

  • php
  • my sql
  • intel
  • cloudlinux
  • nginx
  • cloudflare
  • wordpress