• Sophia Phillips has been working as a professional in WordPrax Ltd­, WordPress website development company and loves sharing information about leveraging multiple benefits of WordPress CMS in the best possible manner. Currently, she has an impressive count of WordPress development- related articles under her name.

How to Duplicate Content in WordPress

Duplicate Content in WordPress

Not all the content on your WordPress website may be unique, as there will be a few posts and pages in the site with a repetitive pattern. In such a case, you'll likely have to make a lot of coping and pasting. Besides, having a copy of page and/or post makes the process of creating multiple posts and pages with similar content (except for titles and a part of content) much easier. This saves you from recreating the same content for each post/page.

What's more? When you're running a WordPress powered online store, you'll probably want to use the same information to be displayed for your long list of products. And so, duplicating the data on the posts/pages will make the task of presenting similar content less difficult for you. Fortunately, there are a few WordPress plugins that makes the task of duplicating posts and/or posts easier for editors; and thus, spare them from copying and pasting the text manually from one post/page to another.

In this post, we'll be discussing about two of the most popular WordPress plugins that enables to copy and paste a page or post without much hassle, namely: Clone Posts and Duplicate Post.

Clone Posts Plugin

The Clone Posts WordPress plugin is an ideal choice for website owners who just want to have a clone of their page or post, without any fluff. In simple words, this plugin lets you create a clone of a WordPress website page and posts, but it doesn't come with an options page. You just need to install this plugin, and you're good to go.When using this plugin, a "Clone" link will be added to all your website post, page, and custom post on the index pages. Whenever that link is clicked, the items on the page/post will be copied and saved as a draft.

Note: Since the copy of the content is kept as a part of drafts in the back-end, you don't have to worry about displaying duplicate data on the front end.

Duplicate Post Plugin

In case, you want to have more options other than the simple copy and paste operation, then you can opt for the Duplicate Post plugin. This plugin provides a complete solution to meet your needs of duplicating the posts or pages compared to the “Clone Posts” plugin. Simply put, it's not just clone your pages and posts on the index pages, but also while displaying them in the editing page or post screen respectively. The Duplicate Post plugin can be used in two different ways to duplicate a post/post:
Duplicate Content in WordPress 1You can choose to click the link named “Copy to a new draft” on the post/page editing screen (as shown in the image below). Doing so, a duplicate copy of the post/page will be opened in a new edit screen.

Note: The "Copy to a new draft" link can be added to the "Publish" section when you're editing a page. Also, it can be added directly to the front end in the admin bar, while you're viewing a page/post on the site.

Simply duplicate any page or post, by navigating to Pages → All Pages (or Posts → All Posts) and hover over the page or post title that needs to be duplicated, and you'll be able to see 2 links “Clone” and “New Draft”, as follows:
Duplicate Content in WordPress 2

When you'll click on the “Clone” button, it will simply copy your page or post but won't open it. On the other hand, clicking on the “New Draft” option will not just copy your page/post, but will also open it on the edit screen.Once you've chosen any one of the above discussed options to duplicate your pages/post, you can even fine-tune the Duplicate Post plugin's behavior – from the settings page in your WordPress site admin dashboard screen. For instance, instead of merely copying the post/page, you can use the settings to copy the blog post's editorial status, attachments and many other things.

Code Your Own

If you've good coding skills and don't want to make use of the WordPress plugins to duplicate your site posts, then below is a code snippet that will help you achieve the same objective with ease:

/*
 * Function for creating a duplicate post
 */
function duplicate_an_post(){
    global $wpdb;
    if (! isset( $_POST['post']) || ( isset( $_GET['post'])  || ( isset($_REQUEST['action']) && 'duplicate_an_post' == $_REQUEST['action'] ) ) ) {
        wp_die('nothing action for creating duplicate post!');
    }
 
    /*
     * post id of real post
     */
    $real_post_id = (isset($_POST['post']) ? $_POST['post'] : $_GET['post']);
    /*
     * data of real post
     */
    $real_post = get_post( $real_post_id );
    /*
     * create the post duplicate, if post data exists
     */
    if (isset( $real_post ) && $real_post != null) {
 
        $args = array(
            'post_title'     => $real_post->post_title,
            'post_type'      => $real_post->post_type,
            'to_ping'        => $real_post->to_ping,
            'menu_order'     => $real_post->menu_order,
            'post_content'   => $real_post->post_content,
            'post_excerpt'   => $real_post->post_excerpt,
            'post_name'      => $real_post->post_name,
            'post_parent'    => $real_post->post_parent,
            'post_password'  => $real_post->post_password,
            'post_status'    => 'draft',
            'comment_status' => $real_post->comment_status,
            'ping_status'    => $real_post->ping_status,
            'post_author'    => $new_post_author
            
        );
 
        $new_id = wp_insert_post( $args );
 
        /*
         * duplicate all post meta
         */
        $real_meta_infos = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$real_post_id");
        if (count($real_meta_infos)!=0) {
            $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) ";
            foreach ($real_meta_infos as $meta_detail) {
                $meta_key = $meta_detail->meta_key;
                $meta_value = addslashes($meta_detail->meta_value);
                $sql_query_sel[]= "SELECT $new_id, '$meta_key', '$meta_value'";
            }
            $meta_query.= implode(" UNION ALL ", $sql_query_sel);
            $wpdb->query($meta_query);
        }
  
        /*
         * At last, open edit post screen as a new draft
         */
        wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_id ) );
        exit;
    } else {
        wp_die('Process failed, Please try again');
    }
}
add_action( 'admin_action_duplicate_an_post', 'duplicate_an_post' );
 
/*
 * Add link for create the duplicate post
 */
function create_option( $actions, $post ) {
    if (current_user_can('edit_posts')) {
        $actions['duplicate'] = 'Duplicate';
    }
    return $actions;
}
 
add_filter( 'post_row_actions', 'create_option', 10, 2 );

Add the above code in your theme functions.php file (or any other file). After executing this code, a Duplicate link will get added to your posts. Clicking this link will create a clone of your posts and will them as drafts.

Conclusion

If you're an editor of a WordPress site, and would like to duplicate some pages and/or posts of the site, reading this post will provide you understanding of the different ways to meet your needs.