How to Duplicate a Page in WordPress

How to Duplicate a Page in WordPress

How to Duplicate a Page in WordPress is a common question which will arise in your mind especially when you are managing a large number of posts or page.

If you are maintaining a predefined post or page structure layout, it will be a time-consuming job to structure your whole post or page every time.

You can create a post or page in WordPress rapidly, but copy pasting same structure every time can become a tedious job.

Obviously, you have to spend most of your time on content research, On-Page SEO and fine tune your post so it can stand out from the crowd.

There can be a scenario when you want to test a same post or page in a little bit different structure of content for example for A/B Testing.

There could be endless scenarios when a question will arise in your mind How to Duplicate a Page in WordPress.

There is no built-in functionality in WordPress which will enable you to duplicate a post or page with a click of a button.

That’s why it is important to learn How to Duplicate a Page in WordPress for WordPress users. You can achieve this very easily. If you are not a programmer and don’t know how to extend WordPress core functionality, don’t worry.

In this post, I will show you How to Duplicate a Page in WordPress with the help of plugin and for this, you don’t need to have programming knowledge.

I will also share a method to add this functionality to your own custom built or premium theme. In result, you don’t have to install a separate plugin to add this functionality. Let’s get started.

What You Will Need

Before we start we do need to make sure you have access to below.

  • WordPress Admin
  • FTP access to your site (Only for developers)

How to Duplicate a Page in WordPress with Plugin

Duplicate Post plugin is one of the most downloaded plugins with over 1 Million active installations, so I will rely on it as I have personally used it and test it.

Not only it allows you to clone or duplicate a post/page but also it provides some extra settings which make duplicating post or page very easy.

You can have a pre-defined suffix or prefix which can be added before or after the title of the cloned page or post. Further, you can also restrict the functionality of the plugin based on the user roles.

Installing Duplicate Post WordPress Plugin

To install Duplicate Post plugin, navigate to the Plugins tab on the left-hand side of your WordPress dashboard. When the page load, click on Add New.

Add WordPress Plugin - How to Duplicate a Page in WordPress
Add WordPress Plugin

Type Duplicate Post in the search bar to search for Duplicate Post plugin and click search.

Search Duplicate Post Plugin - How to Duplicate a Page in WordPress
Search Duplicate Post Plugin

You will have results page something like above and Duplicate Post plugin will be the first one as it has most downloads of all the search results.

Install Duplicate Post Plugin - How to Duplicate a Page in WordPress
Install Duplicate Post Plugin

There will be an Install Now button as shown above. Click on that and install the plugins.

Activating Duplicate Post WordPress Plugin

Newly installed plugins are deactivated by default. In order to proceed and activate the plugin, hit Activate button as shown in below image.

This will activate your plugin and its ready to use.

Activate Duplicate Post Plugin - How to Duplicate a Page in WordPress
Activate Duplicate Post Plugin

Using Duplicate Post WordPress Plugin

From the Dashboard navigate to Posts tab and click All Posts (Posts -> All Posts).

Hover over to the post you want to duplicate and you will notice that two options will be added underneath of Post Title called Clone and New Draft.

Post Clone and New Draft Options - How to Duplicate a Page in WordPress
Post Clone and New Draft Options in Posts Section

The same procedure will be for the pages.

  • You can click on Clone in order to create a cloned version of the selected post.
  • You can click on New Draft in order to create a cloned version of the selected post and to further open it in the post editor. You can then start the editing and choose to either save it as a draft or publish it.

Newly Cloned Post - How to Duplicate a Page in WordPress
Newly cloned post

That’s it, you have successfully duplicated a post. You can use the same procedure to duplicate a page.

Duplicate Post WordPress Plugin Extra Settings

This plugin provides some extra settings to distinguish which post or page is cloned. You can add a suffix or prefix to the title of the cloned post or page.

Follow these steps to add your desired word before or after the title of the cloned post.

From your WordPress dashboard go to Settings -> Duplicate Post.

Duplicate Post Setting Page Link - How to Duplicate a Page in WordPress
Duplicate Post Setting Page Link

From Duplicate Post Options page, you can set the title prefix or suffix which one fancy to you and click Save.

Now every time you clone a post or page, a prefix or suffix (depending on what you have setup) will be added to post or page title.

Duplicate Post Prefix and Suffix Setting - How to Duplicate a Page in WordPress
Duplicate Post Prefix and Suffix Setting

In Duplicate Post settings page, you will find a Permissions tab from this page you can control user levels who can duplicate posts or pages.

How to Duplicate a Page in WordPress without Plugin

If you are a WordPress developer and want to add duplicate post or page functionality to your theme so you don’t have to install an extra plugin, please follow along.

This section will need some level of programming knowledge.

You can code into your theme to add duplicating functionality very easily. Below, you will find the code snippet to enable post or page duplication in WordPress.

/*
 * Function for post duplication. Dups appear as drafts. User is redirected to the edit screen
 */
function webwhistles_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', 'webwhistles_duplicate_post_as_draft' );

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

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

Above code snippet only duplicate posts, not pages. You can use the filter to add the same functionality to WordPress Pages as well.

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

Duplicate a Page in WordPress using WordPress functions.php File

You can add the code snippet to your currently active theme by editing WordPress functions.php file. Navigate to Appearance tab on the left-hand side of WordPress dashboard and click on Editor. On Editor page, choose the functions.php file from right-hand side list of files.

Paste Duplicate Page or Post Code in Code Editor - How to Duplicate a Page in WordPress
Paste Duplicate Page or Post Code in Code Editor

Select Theme Functions (functions.php file) and paste above code snippet into this editor and click Update File file button.

Duplicate a Page in WordPress using FTP

If you are building a custom theme and want to add this code to your theme, open your functions.php file and add the above code snippet.

I would recommend to paste above code snippets in a separate file and then call it in your functions.php file to keep your theme’s functions file tidy. You can call the custom file like below.

require get_template_directory() . '/inc/duplicate-post.php';

inc is a folder inside your theme folder, and the file containing above code snippet called duplicate-post.php.

Upload all files you have changed using an FTP Client to your WordPress installation.

Now if you go to Posts from your WordPress dashboard (Posts -> All Posts) and hover over any post, you will find a new option Duplicate underneath the Post title.

Click This button and it will duplicate the post to a new draft and redirect you to edit post page.

Duplicate option by adding code snippet into your theme - How to Duplicate a Page in WordPress
Duplicate option by adding code snippet into your theme

SEO Check

Although it’s time-saving to duplicate a post or page you have to be careful while duplicating your post or page. If you forget to delete or update the copied content from the new post, Google will consider it as duplicate content.

Make sure you don’t have identical content on your website. You can run a quick check on Siteliner to find all duplicate content.

Conclusion

I hope that above tutorial answered your question How to Duplicate a Page in WordPress and now you know how to duplicate a post or page.

Above recommend plugin is my choice but you can explore more plugins on WordPress Plugins Repository.

Got any questions, tips, or tricks to share? Let us know in the comments!

You May Also Like

About the Author: WebWhistles

Leave a Reply

Your email address will not be published.