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

You are currently viewing How to Duplicate WordPress Page or Blog Post With or Without a Plugin

Have you ever wanted to duplicate a WordPress page to speed up the design process but didn’t know how?

Duplicating a page or post is a practical step that will help you in many ways and, therefore, worth knowing.

In this article, you’ll learn 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 an essential aspect of creating and designing a successful website.

If you designed a page and are satisfied with it, using it only once is a waste. Moreover, starting with a new design on the next page will cost you valuable time and energy. Cloning a page or a custom template will guarantee that the page or the post will look and behave the same.

Often, designing a beautiful page takes a lot of time and thinking. Many elements need to come together to create an appealing design. Trust us, we know. Getting the desired results can take hours or even days; when we finally find them, we want to hold onto them.

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

To be more productive, knowing how to duplicate a page in WordPress will be beneficial to smooth our workflow.

In this article, you’ll learn how to duplicate or clone any page, post, and custom post types, such as Easy Digital Downloads or WooCommerce products.

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.

How to Duplicate Page or Post in WordPress

You can duplicate a WordPress page in three different ways:

  • By using a plugin
  • From the native Gutenberg Editor
  • By using a PHP function (without a plugin)

We will explore all ways, and let’s start with the first way, using a plugin.

Method #1: duplicate a WordPress page with a plugin

In this method, we will use an excellent plugin called Duplicate Page. Many good plugins 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 the page’s screen to see all my pages.

Navigate to all pages

Hover your mouse on the page you want to duplicate and click on the new duplicate This option.

Once clicked, the page will be duplicated and have the same name. However, the newly fresh cloned page won’t be published automatically, and his status will be set to draft.

Page was duplicated

The cloned page contains the same content as the original page, which significantly facilitates duplication.

When ready to push it, edit the newly cloned page by changing its title, content, and slug, and click publish.

Publish the new cloned page

As mentioned above, 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 leaving it that way.

However, you can change the plugin’s setup page if you want to publish them immediately after cloning automatically.

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

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

Duplicate Page Plugin Setting Page

Using a plugin to duplicate a WordPress page is only one of the available ways. In the following sections, I’ll show you how to achieve similar results without using a plugin.

Method #2: duplicate a WordPress page using the Gutenberg editor

Using a plugin is a fast and straightforward way to copy posts or pages, but it’s not the only way. There is another excellent 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 one of the pages you’d like to duplicate.

Click on the three dots icon on the top right corner and choose Copy All Content from inside the edit page.

Copy the content of a page

After copying the content, we will need to create a new page ourselves and paste the content into it. To do that, click on the Add New under the Pages tab.

Create a new page

Then, paste the content 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 is to give the page a title and click publish.

Method #3: duplicate a WordPress page using a function (without a plugin)

If you want to duplicate pages, posts, or custom post types without a plugin, this section is for you.

Code snippets and functions act like plugins but are way less bulky and complicated.

Similar to the plugin we showed you earlier, the function below will also add a duplicate button below each post or page.

You’ll need to paste it inside the functions.php file of your active child theme.

You can access WordPress files with an FTP account such as FileZilla or your website’s dashboard.

We will access our functions file from inside the WordPress dashboard to keep it simple.

Note: please backup your website before editing core files.

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'] = 'Duplicate';
  }
  return $actions;
}
 
add_filter( 'post_row_actions', 'rd_duplicate_post_link', 10, 2 );
add_filter('page_row_actions', 'rd_duplicate_post_link', 10, 2);

Once saved, navigate to the posts or pages screen, and see the new option ‘Duplicate’ option under each list item.

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, publish the new page or post.

Conclusion

This article taught you how to duplicate WordPress pages and post types with or without a plugin.

Leave us a comment and tell us which method from the one above you used to achieve this task.

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

PluginsForWP

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

This Post Has One Comment

  1. Brooke

    I added the code to the php file and it added the word “Duplicate” for pages and posts, but its greyed out?

Leave a Reply