How to duplicate a page in WordPress

0
2540

How to duplicate a page in WordPress is always a big question for those people who are just starting in WordPress. It is not that difficult as you might be thinking now, however, with the release of many page builders like Elementor and Visual composer, it is even more confusing than ever before. In this article, we will show you how you can duplicate a page in WordPress with and without plugins. Furthermore, we will also show you how you can duplicate a page in WordPress using Elementor as well as Visual Composer.

Time and time again we need to duplicate a page in WordPress, So it’s more than necessary to learn how to duplicate a page in WordPress to save time and make no mistake during the copying process. So, without any delay let’s jump to the step-by-step guides on how to duplicate a page in WordPress.

How to Duplicate a Page in WordPress using plugin

Firstly, you need to install Yoast Duplicate Post plugin by Yoast, which is already downloaded for more than 3 million times. After installing it successfully, you need to activate this plugin so that you can start duplicating WordPress pages and posts. To install the plugin, you need to login to the WordPress dashboard then go to PluginsAdd New ➜ then search “Yoast Duplicate Post“.

After successfully activating the plugin. you need to visit PagesAll Pages. There you will see two new options added to each page, i.e, Clone and New Draft.

Duplicate wordpress page using yoast seo duplicate

If you click on Clone, it will create a duplicate page and will immediately be returned to the same list. However, if you want to duplicate a WordPress page and start working on it immediately then clicking on the New Draft would be the better option for you. Because clicking on New Draft will not just duplicate a page in WordPress but also it opens it in the WordPress Editor.

Similar to creating a copy of the WordPress page, you can also duplicate a WordPress post by clicking on either or Clone or New Draft from PostsAll Posts.

Besides, Posts and Pages, it also allows copying Custom Post Types as well. By default, the Clone, and New Draft option will only be visible to the Administrator and Editor. But if you need to show these options for users with other roles as well, then you can do it by visiting SettingsDuplicate Post ➜ and then click on the Permissions tab. There you need to check on those roles whom you want to allow to duplicate a page in WordPress.

Furthermore, you can also change the settings like which elements of a page or post should be copied and which should not be copied. To take a look at what elements to allow to copy you need to select the “What to Copy” tab. From there, you can allow or disallow to copy the title, excerpt, content, featured image, template, slug, date, and many more.

This method of using Plugin to duplicate a page in WordPress is really handy for those who are afraid to play with the text version of WordPress editor.

How to duplicate a page in WordPress without using the plugin

We all know that too much plugin is not that good for WordPress, as it will increase the load time on the WordPress by some milliseconds (and seconds as well if there are too many heavy plugins installed). In case if you are not in the mood of installing an additional plugin just for copying a page or post, then this option is for you. 

To copy a page, open the page you want to clone then click on the 3 dots on the top right corner of the page or posts and click on the copy all content.

Copy all content - Duplicate WordPress Page

On clicking that, all the content will be copied to your clipboard. Now, create a new page by clicking on PagesAdd New. Then, on the content block just paste the copied content either by hitting ctrl+v or by right-clicking and pasting it.

The downside of this method is that it won’t copy other details like featured-image and categories. You have to manually add those extra details of any post. However, it will surely reduce your burden of copying the main content or main page templates.

Add code to duplicate WordPress Page Or Post

If you are not satisfied with the above method’s limitation then you could add this custom code to your theme’s “functions.php” file. Instead of adding this code directly to the theme’s main “functions.php” file, add it on the child theme’s “functions.php” file, otherwise, the code files will be removed when the theme is updated. However, we strongly suggest taking the backup of the WordPress site before making any changes.

/*
 * Function for page duplication. Duplicate appears as drafts and the user will be redirected to the edit screen.
 */
function nt_duplicate_wordpress_page(){
  global $wpdb;
  if (! ( isset( $_GET['post']) || isset( $_POST['post'])  || ( isset($_REQUEST['action']) && 'nt_duplicate_wordpress_page' == $_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 );
 
  /*
   * Current user will be the new post author,
   * To make the same old content author and new author same
   * change $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_nt_duplicate_wordpress_page', 'nt_duplicate_wordpress_page' );
 
/*
 * Add the duplicate link to action list for page
 */
function nt_duplicate_page_link( $actions, $post ) {
  if (current_user_can('edit_posts')) {
    $actions['duplicate'] = '<a href="' . wp_nonce_url('admin.php?action=nt_duplicate_wordpress_page&post=' . $post->ID, basename(__FILE__), 'duplicate_nonce' ) . '" title="Duplicate this item" rel="permalink">Duplicate</a>';
  }
  return $actions;
}
 
add_filter( 'page_row_actions', 'nt_duplicate_page_link', 10, 2 );

The above code will add a “duplicate” link to all pages.

How to Duplicate a page in WordPress without plugins

In case, if you need to add this duplicate link on the post instead of the page then just replace the last filter as follows:

add_filter( 'post_row_actions', 'nt_duplicate_page_link', 10, 2 );

This added code will not just copy the page or post but also copy other post meta like category, tags, featured image and etc.

How to duplicate a page in WordPress Elementor

Although, all the above mentioned worked with Elementor as well. But still, if you are looking to duplicate the design in elementor from one page to another solely using the features provided by the elementor, then this step is for you.

  1. Click on the arrow button next to the update button.

    Save page Template in elementor - to copy a page template
  2. Click “Save as template“, provide the template name, and save it.
  3. Next, open a new page. Edit it with elementor and on the “Drag widget here” section. Click on the folder icon ➜ My templates ➜ Insert the desired template.

    Find Elementor page template
    Insert saved page template elementor - Duplicate a page in Elementor

In this way, you could copy the template and reuse it multiple times in WordPress Elementor.

How to duplicate a page in WordPress Visual Composer

Likewise elementor, visual composer is another popular page builder. So, we are going to cover how to duplicate a page in WordPress using Visual Composer as well. To copy the design in Visual Composer, you just need to follow mentioned procedures step-by-step.

  1. Edit the page with visual composer.
  2. Click on “Add Template” available on the left menu.
  3. Give a template name and save it.

    Create Template in Visual Composer

  4. To copy the saved template, you need to add a new page with a visual composer and click on the same icon as in step 2. Then, load the desired template.

    Duplicate Tempate in Visual Composer

This is it, you can use any of the methods as per your preferences. One method might be suitable for one case and another might be suitable for another case. Among all of them, if you are not afraid to make some changes to the code level, then we would suggest adding the code provided. This will add minimal code without the addition of any other resources. 

LEAVE A REPLY

Please enter your comment!
Please enter your name here