How to Clone a page on WordPress

Spread the love

How to Clone a page on WordPress. WordPress allows users to duplicate pages and posts in more ways than just copying and pasting the content. When revamping your website or upgrading your content, you can also save time by keeping the page template, SEO information, and graphics.

Fortunately, WordPress makes it simple to duplicate pages, posts, and all of the data that goes with them. Both with and without a plugin, there are straightforward methods to complete the task.

In this article, we’ll examine secure ways to replicate a WordPress page or post and introduce some plugins that can be useful. Let’s begin immediately!

How to Clone a page on WordPress

How to Clone a Page on WordPress | Easily Clone a Page in WordPress with These Plugins

When you utilize a WordPress plugin, cloning a page is quite easy because everything is handled inside of your dashboard. Since you won’t be directly changing the code of your website, using plugins is also the safest way to replicate a post or page.

Here are four plugins to consider if you’re looking for the ideal tool.

1. Duplicate Post

Duplicate Post is a popular choice for replicating WordPress pages and posts. This well-liked plugin is simple to use and copies everything, including the comments and page or post text. To distinguish between your original post and the copy, it also provides the prefix and suffix options.

With this tool, all you have to do to duplicate a WordPress article is:

  • Install and activate the plugin.
  • In your WordPress dashboard, go to Posts > All when cloning posts, or Pages > All when cloning pages.
  • Navigate to the original page or post you want to copy, and click on Clone to duplicate it.
  • Multiple pages or posts can be selected, and you can clone them all at once using Bulk Actions.

2. Duplicate Page and Post

Duplicate Page and Post does not have a lot of features but makes up for that in speed.

One of the quickest ways to replicate a post or page in WordPress is to use this small duplicate post plugin, which won’t burden your website with extraneous bells and whistles.

Use the methods below to clone a page or post with this plugin:

  • Install and activate the plugin.
  • Configure its settings to meet your needs.
  • Go to Pages > All or Posts > All to find the content you want to duplicate.
  • Click on the Duplicate This option.

4. Post Duplicator

Another simple cloning plugin is Post Duplicator. Any post or page, including those with custom post types, custom fields, and custom taxonomies, may be duplicated precisely with this approach. It shouldn’t add much weight to your site and is quick and simple to utilize.

Use this tool to replicate material by doing the following:

 

  • Install the plugin and activate it.
  • Navigate to Posts > All or Pages > All to find the content you want to clone.
  • Hover over the post or page.
  • Click on the Duplicate Page or Duplicate Post option.

Duplicating a Page in WordPress Without a Plugin

Of course, using a plugin isn’t required in order to duplicate a WordPress post or page. The funtions.php file can be manually edited, or the necessary code can be copied and pasted. Let’s examine how each approach functions.

1. Enable Cloning via funtions.php Code

Editing the code in your functions.php file is one of the manual ways to copy a WordPress page or post. Although it may be simple to implement, you should exercise caution and first create a backup of your website.

You must use Secure File Transfer Protocol (FTP) or any means you prefer to access your functions.php file and open it for editing in order to enable cloning for posts. Then, you must add the following code fragment to the file’s end:

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

To enable cloning for pages as well, use the same code but replace the final line with:

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

The file can then be saved and uploaded again to your server. Return to your WordPress dashboard after that. When you hover over a page or post that you want to duplicate, a Duplicate button ought to show up.

2. Manually Copy and paste code to Duplicate a Page

You can manually copy and paste the code for the page or post you want to clone if you don’t want to change your functions.php file. To accomplish this, you must:

  • Open the page or post you want to duplicate.
  • Click on the More Tools & Options menu.
  • Select Code Editor.
  • Copy the code for the page or post.
  • Click on New Post or New Page.
  • In the new post or page, open the Code Editor.
  • Paste in the code.
  • Click on the More Tools & Options menu.
  • Open the page or post you want to duplicate.
  • Click on the More Tools & Options menu.
  • Select Code Editor.
  • Copy the code for the page or post.
  • Click on New Post or New Page.
  • In the new post or page, open the Code Editor.
  • Paste in the code.
  • Click on the More Tools & Options menu.
  • Select Visual Editor.
  • The new page or post should now be a clone of the old one.

This process can take a little time, and you’ll need to do it individually for each page or post you want to copy. That’s why we recommend using a WordPress duplicate page plugin if you’re looking to duplicate a lot of content.

 

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Instagram and Facebook.

LEARN FREE WordPress wite Wehavedigitaltool


Spread the love

Leave a Comment

Verified by MonsterInsights