How to Duplicate a Page or Post in WordPress
Duplicating a page or post in WordPress can mean more than simply copying and pasting the content. You can besides retain the page template, SEO data, and images, in orderliness to save time when redesigning your web site or updating your capacity .
fortunately, duplicating pages and posts and all their associated data in WordPress can be easily. There are elementary ways to get the job done, both with and without a plugin .
In this article, we ’ ll look at how to clone a foliate or stake safely, and introduce some plugins that can help. Let ’ s jump right in !
easily Clone a page in WordPress with These Plugins
Cloning a page in WordPress is identical bare when you use a plugin, because everything is done justly in your dashboard. Plugins are besides the safest manner to duplicate a mail or page, since you won ’ thyroxine be modifying your locate ’ randomness code directly.
If you ’ rhenium looking for the right tool, here are four plugins that are worth checking out .
One of the go-to options for WordPress page and post clone is Duplicate Post. This plugin is easy to use, and clones everything from the subject of the foliate or post to the associated comments. It besides offers a prefix or suffix option, to differentiate your original post and the ringer .
To duplicate a post with this cock, you fair need to :
- Install and activate the plugin.
- In your WordPress dashboard, go to Posts > All when cloning posts, or Pages > All when cloning pages.
- Navigate to the page or post you want to copy, and click on Clone to duplicate it.
- Multiple pages or posts can be selected, and you can clone them all at once using Bulk Actions.
Duplicate Page and Post does not have a lot of features, but makes up for that in travel rapidly. This whippersnapper plugin is one of the fastest ways to clone a position or page in WordPress, and won ’ thymine consider your web site down with unnecessary bells and whistles .
To clone a page or post with this plugin, use the pursue steps :
- Install and activate the plugin.
- Go to Posts > All or Pages > All, depending on what you want to duplicate.
- Hover over the page or post you want to clone.
- Click on the Duplicate option.
Duplicate Page offers a few extra features that some early clone plugins don ’ deoxythymidine monophosphate leave. This plugin will duplicate posts, pages, and custom post types. Plus, you can save the resulting copies as drafts, pending, public, or private .
To use Duplicate Page, you equitable need to :
- Install and activate the plugin.
- Configure its settings to meet your needs.
- Go to Pages > All or Posts > All to find the content you want to duplicate.
- Click on the Duplicate This option.
Another simple clone plugin is Post Duplicator. This solution creates an accurate duplicate of any post or page, including custom-made mail types, custom fields, and customs taxonomies. It ’ s agile and easy to use, and shouldn ’ thyroxine add much weight unit to your web site .
To duplicate content with this tool, follow these steps :
- Install the plugin and activate it.
- Navigate to Posts > All or Pages > All to find the content you want to clone.
- Hover over the post or page.
- Click on the Duplicate Page or Duplicate Post option.
Duplicating a page in WordPress Without a Plugin
Of course, you don ’ t have to use a plugin to clone a page or post in WordPress. This can besides be done manually, by either editing the funtions.php file or copy and pasting the relevant code. Let ’ s attend at how both methods work .
1. enable Cloning via funtions.php Code
One of the manual ways to clone a WordPress page or military post is to edit the code in your functions.php file. While this can be easy to do, you do need to be cautious and make a backup of your web site first .
To enable cloning for posts, you ’ ll need to entree your functions.php file and open it for editing, using Secure File Transfer Protocol ( FTP ) or whatever other method acting you prefer. then you ’ ll want to add the be code snip to the end of the file :
/*
* 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 );
To enable cloning for pages adenine well, use the lapp code but replace the final credit line with :
add_filter('page_row_actions', 'rd_duplicate_post_link', 10, 2);
After that, you can save the file and reupload it to your waiter. then you can head back to your WordPress dashboard. A Duplicate push button should now appear when you hover over a page or post you want to clone .
2. Manually Copy & Paste Code to Duplicate a page
If you do not want to edit your functions.php file, you can manually copy and paste the code for the page or military post you want to clone. To do this, you will need to :
Read more: Mochi Ice Cream
- Open the page or post you want to duplicate.
- Click on the More Tools & Options menu.
- Select Code Editor.
- Copy the code for the page or post.
- Click on New Post or New Page.
- In the new post or page, open the Code Editor.
- Paste in the code.
- Click on the More Tools & Options menu.
- Select Visual Editor.
- The new page or post should now be a clone of the old one.
This process can take a short time, and you ’ ll indigence to do it individually for each page or post you want to copy. That ’ south why we recommend using a plugin if you ’ re looking to duplicate a lot of content .
Keep Learning with WP Engine
Streamlining your WordPress feel is easy with page cloning. There are batch of early ways you can save time as well, such as by migrating pages or posts between WordPress sites and even copying development environments .
hera at WP Engine, we offer the best resources for developers wanting to build a great digital experience for their clients. Check out our plans to get started justly away !