How to Duplicate a Page in WordPress –

How to Duplicate a Page in WordPress

Duplicate content isn’t something you want to often have on your site. However, creating copies of your pages – i.e. duplicating them – for consistency is smart practice. Your only concern should be how to get the job done.

Fortunately, there are a few ways to duplicate a page in WordPress, which is to be expected for such a flexible platform. What’s more, there’s a method to suit, regardless of your experience.

In this post, we’ll take a look at four ways to duplicate a page in WordPress. However, before this, let’s dig into why you’d want to do so in the first place.

The Difference Between Duplicating a Page in WordPress and ‘Duplicate Content’

Before we get into specific reasoning, it’s worth discussing the difference between duplicating a page in WordPress, and duplicate content.

The latter relates to Search Engine Optimization (SEO). Duplicate content means much or all of the content on one page on your site is exactly the same as another elsewhere on the web. While it can be a negative, it’s not something a search engine will usually punish you for straight away.

However, this is different to ‘copied content’, which is an explicit attempt to ‘game’ the search engines and rank higher. The penalties for this are much more severe, as the implication is that it’s a deliberate act.

In contrast to all of the above, duplicating your page simply means to copy the formatting, structure, layout, and content. The idea is to use this duplicated page as a foundation for a fresh one, and carries no SEO penality if used for this reason. Let’s talk a little about why you’d want to do this next.

Why You’d Want to Duplicate a Page in WordPress

Admittedly, you’ll likely know when you’re in a situation that requires you to duplicate a page in WordPress. However, it could be that your current methods of creating posts and pages would benefit from a more efficient approach. For example:

  • You have a specific layout in mind for your current page that’s found elsewhere on your site.
  • You may create ‘drafts’ of pages that you often reuse when creating new content (for example, blog posts).
  • There is custom HTML or CSS code found in one layout that you want to use in a new page.
  • You might want to work on a new version of a page, and don’t have staging functionality available to you (although there are better ways to do this).

All of these situations would benefit from a shortcut in terms of duplicating your page. As such, let’s tackle the solutions we recommend in the next section.

How to Duplicate a Page in WordPress (4 Methods)

For the four methods below, we’ll go from relatively easy to moderately difficult depending on your experience. Here’s what we’ll cover:

  1. How to copy and paste your content manually (and why you shouldn’t).
  2. Use the Block Editor to copy your content.
  3. Install a plugin to duplicate a page.
  4. Add code to your functions.php file to duplicate pages.

Once we’re done, we’ll then give you some advice for choosing the best way to duplicate a page in WordPress.

1. Copy and Paste Your Content Manually (And Why It’s Not Ideal)

First off, let’s discuss the traditional approach many will take. The ‘brute force’ tactic to duplicating a page in WordPress is to simply copy the content and paste it into a new draft.

If you’re shrugging at the page while reading this, we’ll bet you’re in one of the following camps:

  • Your site has few pages, and uses little SEO or taxonomy fields.
  • The page you’d like to duplicate is not accessible through the back end of your site.
  • You haven’t discovered a quicker way.

If you agree with either of the first two points, copying and pasting is going to arguably be the best way to proceed.

However, while manually copying and pasting is simple to understand and execute, there are a few drawbacks. This approach won’t correctly copy over images, categories and tags, meta descriptions, permalinks, or any under-the-hood elements of your site such as custom HTML.

Step 1. Copy the Text From the Original Article

CTRL-A is your friend here, and the steps aren’t complex either:

  1. Access the site in question.
  2. Highlight and copy the text.
  3. Paste it into your new draft.

This should be straightforward for even the most ‘tech-deaf’. However, the next step is slightly more tricky.

Step 2. Remove Tags From Your HTML

Note that depending on your source and target drafts, you may need to re-apply heading formats and also remove superfluous HTML from the back end. To do this, access the code editor of your page once you’ve copied the content over. Classic Editor users should click on the Text tab…

…and Block Editor users will want to head to the Code editor:

The Block Editor's Code editor screen.

From here, it’s wise to remove any &amp;nbsp; or <span> tags you find. Our advice is to take a look at a non-duplicated page and follow the structure and layout of the code.

Given the work, it could become a time sink for more than one or two pages, and every manual duplication has the potential to introduce errors and mistakes.

Instead, it’s better to consider another of the options in this list if you want to efficiently duplicate a page in WordPress without errors and wasting time.

2. Consider Using the Block Editor’s Functionality to Help You Duplicate Pages

Using the Block Editor to duplicate a page in WordPress is more of a ‘semi-manual’ approach, given that most of the drawbacks are still valid.

However, if you have a page within your own WordPress site that you’d like to duplicate, open the page, and look to the More tools &amp; options menu in the top right-hand corner of the screen:

The More tools button in WordPress.

Once you open this menu, move to the Tools section, and click Copy all content. From here, you can paste the content into a fresh draft and begin to work on it. However, it’s still not the most efficient way to duplicate a page in WordPress.

3. Use a WordPress Plugin to Duplicate Your Page

Practically everything within WordPress can be achieved using a plugin, and duplicating pages is no exception.

Your first job here is to choose something suitable. You’ll want to look at plugins that have been updated within the last six months, work with your version of WordPress, and have good ratings and reviews (at least four stars).

There are a few recommendations here. Yoast Duplicate Post and Duplicate Page or Post are both well-received and consistently maintained. However, let’s give you an example using the Duplicate Page plugin, which is arguably the best solution available:

The Duplicate Page plugin.

Once it’s installed and activated, head to your Pages > All Pages screen within WordPress. From here, hover over the page you’d like to duplicate, and look for a Duplicate This link:

The Duplicate This link.

Clicking this will clone the page in question – job done!

4. Add Code to Your functions.php File to Duplicate Your Page in WordPress

Our final method is arguably the toughest to implement, but offers the greatest flexibility and implementation. Adding code to your functions.php file is great for many tasks, not least duplicating pages in WordPress.

You can add a link directly to your Pages dashboard screen, which means it’ll always be there when you need it. However, before you begin, you’ll need some things in place:

  • A suitable text editor. Atom, Sublime Text, or Notepad++ are all free (or come with trials), and even a default text editor will do in a pinch.
  • A File Transfer Protocol (FTP) client. FileZilla or CyberDuck are great choices, and will give you a nice way to access your site. Your hosting provider may also offer a File Manager, which does the same thing.
  • Access to your site’s server. The credentials for this can usually be found within your hosting control panel, or through an email sent to you when you first purchased an account.
  • The skills to manage your site through FTP. If this is something you need to brush up on, the Make WordPress website has a great FileZilla tutorial that can be adapted to other clients.
  • A child theme based on your current parent theme. This helps preserve your changes when updates are made, and we’ve discussed how to do this in the past.

Once you’re ready, open up your FTP client, and follow along!

Step 1. Open Your functions.php File

First, log into your site through your FTP client, and look for the wp-content > themes folder:

The wp-content > themes folder.

Inside, should be your child theme’s folder containing a functions.php file. It may not be there, in which case you’ll need to create it first. Next up, is editing it.

Step 2. Add Code to Your functions.php File

Once you have your functions.php file open, you’ll want to add the following code. It should go after all of the other code that’s potentially in there:

/* Duplicate posts and pages function. Duplicates appear as drafts, and the 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;

/* This gets the original post or page ID */
$post_id = (isset($_GET['post']) ? absint( $_GET['post'] ) : absint( $_POST['post'] ) );

/* …then grabs the original post data. */
$post = get_post( $post_id );
     
/* To select another user as the post author, use $new_post_author = $post->post_author;. Otherwise… */
$current_user = wp_get_current_user();
$new_post_author = $current_user->ID;
     
/* If the post data exists, create the duplicate */
if (isset( $post ) && $post != null) {
    /* Create a 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 using wp_insert_post() */
        $new_post_id = wp_insert_post( $args );
     
        /* Get all current post terms, then set them against the new 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 of the post metadata */
        $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);
        }
     
        /* 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 the 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 );

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

Once you’ve added the code, save your changes and log out of your FTP connection.

Step 3. Check You Can Duplicate a Page

Finally, refresh your back end and head to your Pages screen. You’ll see the duplication link appear as before:

The Duplicate link in WordPress.

With the right knowledge, you could easily turn this into a plugin and expand on the functionality even further, although it works great sat within your child theme’s functions.php file.

How to Choose the Right Method to Duplicate Your Page in WordPress

When it comes to duplicating your pages, the tendency to opt for the quickest solution makes sense. However, in our opinion, you may want to consider a more complex option depending on your needs.

For most users who simply need to duplicate a page in WordPress, a plugin is going to be your best bet. You can install and activate it when necessary, and it will give you the functionality you need (and more in some cases).

However, if you’re a heavy ‘duplicator’, potentially with complex needs, hardcoding a solution to duplicate your pages in WordPress makes perfect sense. It will always be there, and will deliver a custom experience based on your needs.

Of course, there’s also a budgetary concern in some situations depending on those needs, but if you’re getting the functionality you want, it’s money worth spending.

Wrapping Up

On the surface, a task such as duplicating a page in WordPress should be a simple button push. Depending on your experience and knowledge, some approaches can seem much more complex.

In this post, we’ve looked at four ways to duplicate a page in WordPress, with varying degrees of difficulty. Let’s quickly recap them:

  1. Copy and past your content manually, although be prepared to sink time into the task if you have a lot of pages.
  2. Alternatively, use built-in Block Editor functionality – although a more robust solution is better.
  3. Take the classic approach and use a plugin to duplicate your pages, such as Duplicate Page.
  4. Crack open a text editor and add code to your WordPress functions.php file.

Are you looking for a way to duplicate a page in WordPress, and if so, which of these options appeals to you? Let us know in the comments section below!

Keep reading the article at WPKube. The article was originally written by Tom Rankin on 2021-03-16 13:29:00.

The article was hand-picked and curated for you by the Editorial Team of WP Archives.

Disclosure: Some of the links in this post are "affiliate links." This means if you click on the link and purchase the product, We may receive an affiliate commission.

Leave a Comment

Your email address will not be published. Required fields are marked *

Show Your ❤️ Love! Like Us
Scroll to Top