How To Copy Or Duplicate WordPress Pages Or Posts (2024)
How To Duplicate Pages or Posts
- Install the Labinator Content Types Duplicator plugin.
- Go to your dashboard.
- Go to Pages or Posts.
- Hover over a page or post.
- Click on “Clone”.
Introduction
Your pages and posts are the bread and butter of your WordPress site. This makes it essential to know how to edit and create them with ease. Duplicating is an amazing tool to have because it allows you to not only duplicate existing things but also create templates that you can clone to create content.
Duplication can significantly speed up your workflow and allow you to work much more efficiently. Although it may seem hard to set up, enabling cloning or getting one of these plugins to help you duplicate pages or posts is very easy. In this tutorial, I will show you how to clone content without plugins and how to use plugins to clone them.
Duplicating With No Plugins
To start, this section will show you how to do without a plugin. Using this code you add to your functions.php file cloning can be enabled manually. To do this, you will need to be able to use an FTP or cPanel to access your WordPress site’s core server files.
If you want an FTP to start with, FileZilla is a great choice. Some hosting providers come built-in with a cPanel that lets you access files. Once you have set up your cPanel or FTP, you backup your site before proceeding for extra safety. To start the process, you must find your WordPress server files and follow the steps below:
Open your FTP or cPanel.
Find and open the functions.php file.
Go to the bottom of the file and add this code:
/*
* 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;
}
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 finished the processes as we’ve listed you can duplicate pages or posts. Your WordPress now has duplication for pages and posts enabled. This method will allow you to duplicate pages and posts exactly like how a plugin would. To duplicate pages or posts follow the steps below:
- Go to your WordPress dashboard.
- Go to Pages or Posts.
- Hover over the page or post you want to duplicate.
- Click on Duplicate.
The only downside to this method is that you cannot duplicate pages or posts in bulk or with special settings. Plugins allow for more customizability and options as to how you want to duplicate pages or posts. In the next section, I will show you how to use plugins to duplicate pages or posts.
Duplicating Using Plugins
If you want an all-in-one duplicator for your posts, pages, media files, menus, widgets, and any custom content types then our own free plugin would be the perfect choice for you. The “Labinator Content Type Duplicator”. This plugin is incredibly lightweight, fast, easy-to-use, and can duplicate pages or posts with custom settings. This plugin is the best because it can do everything in one place with one install.
The “Labinator Content Types Duplicator” does exactly what it says, it allows you to duplicate any content type on WordPress however you would like. This free plugin offers several extra features and a lot of capability for how content is duplicated. See how to use the plugin here:
- First, install and activate the plugin.
- Go to Pages or Posts, depending on which you want.
- Hover over the page or post you want to clone.
- Click on Clone.
As you can see, with the help of this handy plugin, you can duplicate pages or posts in four easy steps. This plugin is a very good choice for cloning pages and posts without very much effort. Though that is not the only thing this plugin is capable of. In the next section, I will show you how to duplicate content with custom settings.
Duplicating With Custom Settings
The best method for custom duplication is using the plugin called “Labinator Content Types Duplicator”. As previously mentioned, this plugin can do pretty anything when it comes to duplication. That also includes custom duplication of certain content types. The plugin has a built-in page that allows you to change the content types, access permissions, and add other settings.
The plugin does this by providing an entire settings screen instead of just one button. The plugin already provides options for duplicating widgets and media, in their respective areas. The settings screen allows you to set the criteria you want to use to change how the pages and posts are duplicated. See how to use it here:
- Go to your WordPress dashboard.
- Go to Settings.
- Then go to Labinator Content Types Duplicator.
The first menu allows you to change what is being cloned and how it is being cloned. You can change what you can duplicate as well as the elements that are being duplicated. This page also allows you to change the suffix and prefix of your cloned content.
The second and third menus on the plugin screen allow you to change the permissions for the plugin and the display options. The permissions tab allows you to give access to certain admins and users on your site. The display options allow you to change where the links for content appear.
Now you know how to duplicate pages or posts in WordPress with plugins, without plugins, and with custom settings. Using this process, you will able to duplicate and clone pages or posts to your liking and with ease. If you want more awesome plugins then you should check out this site!
The Best Place for WordPress Solutions
Having to deal with things with technical problems and errors can make using WordPress painful. Though we have the perfect solution for you!
Our top of the line WordPress solutions have you covered for everything from themes and plugins to live support. With us by your side, you will have a clean, optimized, and polished site in a couple of days!
WordPress Guides
Best Collection Of WordPress Guides & Checklists
Our complete and latest collection of WordPress guides and resources that cover everything you need to get the most out of your WordPress website.
Download Them All!
All of our guides will be sent to your inbox