Recently updated on January 12th, 2024 at 03:59 pm
When you redesign your website or update content, cloning an existing WordPress page as a template will save you a tonne of time. It makes it so you never have to start from scratch, allowing you to duplicate everything, including images, SEO data, tables, lists, headings, and more.
Cloning a page can be done with or without plugins in WordPress, with each method having its own benefits. Let’s have a look at some of your options:
Cloning an existing WordPress page with plugins
Duplicate Post
Duplicate Post is one of the best options for cloning a WordPress page or post. This plugin lets you duplicate all page content, including associated comments. If you want to distinguish the clone from the original content, you can use the prefix/suffix option. Here’s how you can duplicate a page or post with this plugin:
- Install and activate Duplicate Post.
- If you’re cloning posts, go to Posts > All in your WordPress dashboard. If you’re cloning pages, go to Pages > All.
- Select the content you wish to duplicate, then click Clone.
If you want to copy multiple pages or posts, just go to Bulk Actions to clone them all at once.
Duplicate Page and Post
Although Duplicate Page and Post has fewer features than other plugins, it’s very easy to use. This lightweight plugin should be compatible with any site, cutting unnecessary bells and whistles to integrate into your WordPress infrastructure without any hassles. Follow the steps below to use this plugin:
- Install and activate Duplicate Page and Post.
- If you’re cloning posts, go to Posts > All in your WordPress dashboard. If you’re cloning pages, go to Pages > All.
- Select the page or post you want to copy and click on the Duplicate option.
Duplicate Page
If you’re looking for more options when cloning a page or post, you can use Duplicate Page. Aside from cloning pages, posts, and custom formats, this plugin also allows you to save clones as drafts and set accessibility as pending, public, or private. Using this plugin is still very straightforward, simply:
- Install and activate Duplicate Page.
- Configure its settings according to your page requirements.
- If you’re cloning posts, go to Posts > All in your WordPress dashboard. If you’re cloning pages, go to Pages > All.
- Select the page or post you want to copy and click Duplicate This.
Post Duplicator
Post Duplicator is another go-to option for cloning a page or post. This cloning plugin duplicates a page or post from its custom fields, custom post types, and even custom taxonomies. It’s quick and easy to use, and doesn’t add much weight to your site. Use this tool by following the steps below:
- Install and activate Post Duplicator.
- If you’re cloning posts, go to Posts > All in your WordPress dashboard. If you’re cloning pages, go to Pages > All.
- Select the page or post you want to copy and click Duplicate Page or Duplicate Post.
Cloning an existing WordPress without a plugin
Using functions.php Code
Editing the functions.php file is the hands-on alternative to using plugins in your WordPress site. This file contains template information, automatically activating when you select your current theme, and uses PHP code to change or add features to your site.
Changing the functions.php file using custom code unlocks a lot of customisation for your site, including page or post cloning features. It’s a lot easier than it looks, but we always recommend that you create a backup of your website before making any changes to code.
Once your backup is ready, just follow the process below:
- Access your functions.php file and open it for editing. You can find it through the WordPress dashboard in Appearances>Theme Editor.
- Add the following code snippet at the end of your file to enable functionality to clone a post:
/*
* Function for post duplication. Dups appear as drafts. 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;
/*
* 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'] = 'Duplicate';
}
return $actions;
}
- Or if you’d like to clone a page, replace the final line of the code snippet (beginning with ‘add_filter’) with the following: add_filter(‘page_row_actions’, ‘rd_duplicate_post_link’, 10, 2 );
- Save your changes.
Now, when you navigate to your WordPress dashboard, you should be able to see a Duplicate button when you click on a page or post.
Copying and Pasting Codes
Another way to clone an existing page or post is through copying and pasting the source code of the content you wish to duplicate. Here’s how to do it:
- Select and open the page or post you want to clone.
- Click More Tools & Options.
- Select Code Editor.
- Copy the code for the page or post (a quick ctrl+a, ctrl+c will do the trick).
- Click New Post to copy a post; click New Page to copy a page.
- Open the Code Editor in the new post or page you created.
- Paste the copied code.
You can then check if the content has copied across correctly by going back to More Tools & Options and selecting Visual Editor.
Note: one drawback of using this method is that it takes a lot of time to duplicate a page. You’ll have to repeat this process for every page or post you want to clone, so we don’t recommend it if you want to clone content in bulk.
Content cloning saves you time
There are many ways to clone a page or post, but all of them save you time by letting you work from a content template. If you can implement a consistent structure across your pages and posts, you’ll find content creation becomes easier and more flexible with a quick cloning process.
Contact us for Website Maintenance & WordPress Support Services in Sydney