How To Duplicate A WordPress Page Or Post With A Single Click

Duplicate a WordPress Page or Post with a Single Click

When building a new website, many people are turning to WordPress for help. WordPress is widely use and considered as one of the best website building platform for 2017. This is because this awesome platform offers numerous ways to build striking web pages without a single line of code. On top of that, WordPress also makes it easy to add new content to existing pages and change their design without technical difficulties.

✎ Read Also: 13 Powerful & Hidden WordPress Features You Can Use in 2017

Let’s say that you spent hours on perfecting the design of your online store. You’ve created a spectacularly designed page that showcases your product in the best way possible. Now, you want to use that same page for other products, so you’ll naturally want to duplicate your master product page. However, you’ll soon see that WordPress can’t do that on its own. Don’t worry, since we are here to tell you how to duplicate a page in WordPress.

Why Cloning/Duplicating a Page/Post in WordPress is a Good Idea?

By duplicating a web page or post, you’re making an exact copy of your original page. This often includes graphics and text elements, page titles, and even SEO data. This is very useful if you’re redesigning your website and want to save a copy. Additionally, this is how you can copy a blog post that’s already perfectly designed and formatted. Replace the text and images, and you have your new post prepared for publishing in no time.

If you continue reading, you’ll get to learn how to duplicate a page in WordPress. We’ll be taking a look at adding this functionality through code that might be the right fit for those of you who like to tinker with back-end code. For those who’d rather avoid messing with code, we’ll show an easy-to-use plugin that gets the job done.

✎ Read Also: 5 Reasons Upgrading to the Latest Version of WordPress Shouldn’t Go Unnoticed!

How to Duplicate a WordPress Page/Post with Plugin?

The majority of WordPress users tend to use plugins that extend or bring new features. You can create a WordPress duplicate page using a plugin called Duplicate Post. Here’s how to install and use it.

  • First, you need to download and install Duplicate Post. This is done within WordPress’ Plugins section found on the left-hand side. You’ll see a search box that can be used to search and find this plugin.

Duplicate headings on wordpress Step 1

  • After installing Duplicate Post, don’t forget to activate it. Hover over the plugin’s name and click on Activate. Now you’ll be ready to use it.
  • Navigate to Posts > All Posts and hover over the post you’d like to copy. You will see two new options appear under the post’s name: Clone and New Draft. If you’d like to copy your post, click on Clone. The other option also clones your post, but also automatically opens the cloned post so you can edit it right away.
  • After a second or two, you’ll see your newly cloned post that has the same name as the original, but this one will be saved as a draft.
  • You can edit it, and publish it when you’re ready.

Every time you clone a post, you’ll see that the new post is identical to the original. You can edit it, add or remove other elements. Once you’re ready, publish the post.

It is also worth noting that you can fine-tune this plugin to clone other kinds of data like comments, titles, slugs, and other things. This is useful to know if you’re not just cloning and creating a new post, but redesigning your website.

How to Customize the Duplicate Post Plugin in WordPress

Let’s take a look at how Duplicate Post can be customized. This way, you don’t only duplicate page in WordPress but also other elements connected to that page. For example, you can clone comments, attachments, titles and dates, and more.

To edit the plugin, go to Settings > Duplicate Post. This is where you’ll see three tabs named What to Copy, Permissions, and Display.

  • What to Copy: This tab allows you check what kinds of content this plugin duplicates. We’ve shown you how to duplicate a page in WordPress, but this is how you can fine-tune this functionality. This tab also allows you to add prefixes or suffixes to easily distinguish newly cloned pages from the rest.

Duplicate headings on wordpress Step 2

  • Permissions: By default, administrators and editors are allowed to use this plugin. You can allow other authors or contributors to access this feature.
  • Display: The third tab allows you pick where you’d like to see links toward cloned pages. By default, the clone post links show on post list, edit screen, and admin bar.

Once you’re done editing Duplicate Post and fine-tuning the way you duplicate pages in WordPress, don’t forget to click Save.

WordPress Duplicate Page via Code

If you’re afraid that adding another plugin will slow down your site, you can tinker with WordPress’ code. By adding a series of code lines to your theme’s functions.php file, you can gain WordPress Duplicate Page functionality. Here’s how it’s done:

We’ll be dealing with your theme’s functions.php file. This file is found under the Appearance section > Editor. Now pick the functions.php from the right-hand side of the present files.

Duplicate headings on wordpress Step 3

  • Once you’ve opened functions.php, add the following code:

/*
* Function creates post duplicate as a draft and redirects then to the edit post 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 );

  • This code will enable WordPress to duplicate your posts. If you’d like to extend this functionality to pages, alter the final line to this:

add_filter(‘page_row_actions’, ‘rd_duplicate_post_link’, 10, 2);

That’s it! Thanks to the code we provided, you hopefully avoided having to install a plugin. In addition, there’s always that kind of satisfaction of tinkering with code and adding new functionality to WordPress this way.

✎ Read Also: How to Remove and Hide Page Title in WordPress for Increased Visibility

Conclusion

We hope that we have provided everything you need to know about your ‘How to duplicate a page in WordPress’ questions. As you now know, you can either dive into WordPress’ code or use a very simple plugin to get the job done.

It is true that certain plugins can affect your website’s performance, so make sure you double-check if a certain plugin is credible. Duplicate Post is a very simple yet powerful plugin, so you don’t have to be afraid of messing up the load time of your website.