How to Duplicate a WordPress Page Without Plugin

Duplicating a page in WordPress can be very useful for creating new content quickly while maintaining a consistent layout and design. However, installing a plugin just for duplicating pages can slow down your site. Fortunately, there are a couple easy ways to duplicate a page in WordPress without needing any plugins.

Why Duplicate a Page?

Here are some common reasons you may want to duplicate a page in WordPress:

  • Save time when creating new content – Rather than building each new page from scratch, duplicating an existing page allows you to reuse the same layout, images, styling, etc. This saves a ton of time compared to creating each new page completely from scratch.
  • Maintain consistent design – When you duplicate a page, the new page inherits the same theme layout, styling, images, etc. This helps keep the user experience consistent across your site.
  • Test changes – Duplicating a page is useful for testing changes without affecting the original. You can experiment with new layouts, content, SEO changes, etc. on the duplicate before implementing them on the live page.
  • Create translated versions – Duplicating a page provides a quick starting point for creating translated versions of a page by only needing to translate the text content.

Method 1: Duplicate Page Plugin

The easiest way to duplicate a page is by using a plugin like Duplicate Page. Here are the basic steps:

  1. Install and activate the Duplicate Page plugin
  2. Navigate to Pages > All Pages in your WordPress admin dashboard
  3. Hover over the page you want to duplicate and click Duplicate This

That’s all there is to it! The plugin automatically duplicates the page and all its content, metadata, featured image, etc.

However, if you don’t want to use a plugin, there is another method using code.

Method 2: Using Code

Duplicating a page without a plugin requires adding a small snippet of code. Here’s how:

  1. Access your theme’s functions.php file, usually located in /wp-content/themes/your-theme/
  2. Add the following code:
function rd_duplicate_page_as_draft(){
  global $wpdb;
  if (! ( isset( $_GET['post']) || isset( $_POST['post'])  || ( isset($_REQUEST['action']) && 'rd_duplicate_page_as_draft' == $_REQUEST['action'] ) ) ) {
    wp_die('No page 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_page_as_draft', 'rd_duplicate_page_as_draft' );

/*
 * Add the duplicate link to action list for post_row_actions
 */
function rd_duplicate_page_link( $actions, $post ) {
  if (current_user_can('edit_posts')) {
    $actions['duplicate'] = '<a href="' . wp_nonce_url('admin.php?action=rd_duplicate_page_as_draft&post=' . $post->ID, basename(__FILE__), 'duplicate_nonce' ) . '" title="Duplicate this item" rel="permalink">Duplicate</a>';
  }
  return $actions;
}

add_filter( 'page_row_actions', 'rd_duplicate_page_link', 10, 2 );
  1. Save changes to functions.php

Now you will see a “Duplicate” link when viewing pages under Pages > All Pages. Simply click this link to create a duplicate as a draft.

When Should You Duplicate a Page?

Duplicating pages can be useful in many cases, but there are also some downsides to be aware of:

Use cases:

  • Reusing successful page layouts and content for new pages
  • Testing changes on a duplicate before updating live pages
  • Creating translated page versions by duplicating then translating the copy
  • Maintaining consistent page templates across a site

Downsides

  • Can lead to duplicate content issues if multiple live pages have the same or very similar content
  • Duplicated pages may have broken links, images, etc. that need to be updated
  • Too many duplicates can complicate site maintenance and updates

So in summary, duplicating pages can speed up your workflow but be cautious of potential downsides. Always thoroughly test duplicates before making them live. And focus on creating pages that serve a unique purpose to avoid duplicate content penalties.

Final Thoughts

Duplicating a page in WordPress is easy using the Duplicate Page plugin or a small code snippet. It allows you to quickly reuse successful page layouts and content.

Just be thoughtful in how you utilize duplicates to avoid issues like duplicate content, broken links, etc. Test all changes on duplicates first before updating any live pages.

Used judiciously, duplicating WordPress pages can save huge amounts of time compared to building each new page completely from scratch. It helps maintain visual consistency and allows for easy translations.

So now that you know how to duplicate pages in WordPress without plugins, go give it a try! Let us know in the comments if you have any other tips or tricks for duplicating WordPress pages.

Additional Tips for Page Duplication in WordPress

Avoid SEO Pitfalls

When duplicating pages, it’s crucial to address potential SEO challenges. Duplicate content can confuse search engines, leading to lower rankings or keyword cannibalization. Always update the duplicated page’s title, URL slug, and metadata to ensure it serves a unique purpose.

Streamline Your Workflow

If you frequently duplicate pages, consider creating templates for commonly used layouts. This approach can save time and reduce the need for repetitive duplication. WordPress page builders like Elementor or Divi allow you to save templates that can be reused across your site.

Use Canonical Tags

For instances where duplicate content is unavoidable (e.g., translated pages or A/B testing), implement canonical tags. These tags inform search engines about the primary version of the page, helping to maintain your SEO integrity.

FAQ

What’s the difference between duplicating a page with a plugin and manually?

Using a plugin is faster and more user-friendly, especially for beginners. Manual duplication offers more control but requires technical knowledge, such as editing the functions.php file or copying HTML code.

Can I duplicate custom post types?

Yes! Many plugins, including “Duplicate Page” and “Yoast Duplicate Post,” support custom post types like product pages or portfolio items.

How do I ensure my duplicated page doesn’t harm my site’s performance?

Always check for broken links, missing images, or outdated scripts on duplicated pages. Additionally, avoid publishing duplicates without unique content updates to prevent SEO penalties.

Are there alternatives to duplicating pages for similar layouts?

Yes! Consider using reusable blocks in the WordPress Block Editor (Gutenberg) or creating global sections in page builders like Elementor. These methods allow you to replicate design elements without creating full-page duplicates.

For more insights on managing WordPress efficiently, explore guides on optimizing site performance or enhancing your content strategy!