How to duplicate a page on WordPress

George Rossoshansky
SEO Expert, Team Leader, Rush Academy Speaker George Rossoshansky

How to copy a WordPress site using a plugin Yoast Duplicate Post 

STEP 1

If you want to copy or recreate multiple WordPress posts, you should use a plugin. We’ve chosen for you an option that quickly duplicates content without unnecessary features. Follow our step-by-step instructions or read the quick guide.

Log in to your WordPress admin page and click “Plugins” in the menu on the left. Then click on “Install”.

STEP 2

Now search for the “Yoast Duplicate Post” plug-in in the “Search for plug-ins…” search box. Then install the plug-in via Install Now. Once installed, go to “Activate”.

STEP 3

Now switch to the “Messages” entry and copy the message using the new “Duplicate” or Duplicate Message button. You will then receive a copy of your contribution 1:1.

How to copy a WordPress site using a plugin Duplicate page

If you want something simple and easy to use, Duplicate Page is your plugin. Duplicate Page is a plugin that allows you to duplicate pages, posts and custom entries on WordPress. It allows you to save cloned content as draft, private, public or pending, depending on how you set it up before you start working with it.

You can download Duplicate Page for free straight from the official WordPress repository, but the plugin offers improvements in its premium version: more configuration options, access to plugin features by filtering by user type, plugin activation in different content types, redirects after cloning.

The first thing you need to do is log into your WordPress control panel, install the plugin and activate it. Before you start using it, familiarize yourself with the duplicate page configuration options. Go to Settings > Duplicate Page:

How to copy a WordPress site manually without a plugin

If you want something simple and easy to use, Duplicate Page is your plugin. Duplicate Page is a plugin that allows you to duplicate pages, posts and custom entries on WordPress. It allows you to save cloned content as draft, private, public or pending, depending on how you set it up before you start working with it.

You can download Duplicate Page for free straight from the official WordPress repository, but the plugin offers improvements in its premium version: more configuration options, access to plugin features by filtering by user type, plugin activation in different content types, redirects after cloning.

The first thing you need to do is log into your WordPress control panel, install the plugin and activate it. Before you start using it, familiarize yourself with the duplicate page configuration options. Go to Settings > Duplicate Page:

You will need to set up duplicate pages according to your needs:

  • Status of duplicate entries: When a plugin is going to duplicate pages or entries, it must assign a status to that content. WordPress has 4 states for a record or page: Eraser, Pending, Public and Private. Its default status is ‘Creation’ and, from my point of view, it’s the most appropriate and the one I recommend you leave configured.
  • Where to redirect to after duplication: When a plugin duplicates content, two things can happen: you appear in the list of pages or posts (if necessary) or in the edit panel of the post or page you just duplicated. You decide.
  • Duplicate input suffix: when the plugin duplicates content, it adds a suffix to the name of the post or page. This name will appear after the title.

Once you have everything to your liking, click ‘Save’ and you’re done. You can now start using duplicate pages.

If you want to clone a page on WordPress, go to: Pages > All Pages and hover over the page you want to copy. You will see that the Duplicate option will appear.

Click the button and you’re done! Your page has already been duplicated.

If you want to duplicate a post or entry on WordPress, go to: Posts > All Posts and hover over the entry you want to copy. You’ll see that the “Duplicate” option will appear (as before). The procedure is the same for both pages and posts.

IMPORTANT

The code I’ll show you below, you have to add it to your theme’s functions.php. Specifically, alfunctions.php of your child theme. If you don’t have it, it’s time to create a child theme. This way, you won’t lose changes with major theme updates.

/** FUNCION 1: Adding the clone button to pages and posts
*/function insertar_boton_duplicar($acciones,$post) 
{
//If the user has permissions to edit entries and pages, then the clone button can be displayed.
if(current_user_can('edit_posts'))$acciones['clone']='<a href="'.wp_nonce_url('admin.php?action=duplicar_contenido&post='.$post->ID,basename(__FILE__),'clone_nonce').'" title="Duplicar este contenido" rel="permalink">Duplicar</a>';
return $acciones;
}
/*
* The function is added to the list of actions for posts and pages.
*/add_filter( 'post_row_actions', 'insertar_boton_duplicar', 10, 2 ); //Entradas
add_filter( 'page_row_actions', 'insertar_boton_duplicar', 10, 2 ); //Paginas

The second function collects all the information from the post or page you want to copy and creates a draft with this data: title, author, metadata, taxonomy, text… It will only fail if it does not get the content identifier right, if the original content does not exist or if the insertion into the database was not possible.

FUNCTION 2: Create the draft content
*/function create_draft($id=0){
//Check that a valid id (other than 0) is received. If it is not valid, the
function is terminated and no action is taken.
if(!$id) return 0;
//Checking that the id is valid, the post data with that identifier is retrieved
and checked if it exists or not.
$post = get_post( $id );
if (isset( $post ) && $post != null)
{// The data needed to make the cloning is collected: the user, the title, the type, the author… everything related to the content to be cloned.
$data = array(

post_title’ => $post->post_title,
‘post_name’ => $post->post_name,
‘post_content’ => $post->post_content,
‘post_excerpt’ => $post->post_excerpt,
‘post_parent’ => $post->post_parent,
‘post_type’ => $post->post_type,
‘post_status’ => ‘draft’,
‘post_password’ => $post->post_password,
‘post_author’ => $post->post_author,
‘ping_status’ => $post->ping_status,
‘to_ping’ => $post->to_ping,
‘comment_status’ => $post->comment_status,
‘menu_order’ => $post->menu_order
);
//wp_insert_post inserts the contents of the previously constructed object into the database

$delete_id = wp_insert_post( $data ); //If the database insertion was not successful the identifier is invalid. if($delete_id) { //If the insertion was successful. The taxonomies and meta content are copied from the original to the draft. $taxonomies = get_object_taxonomies($post->post_type); foreach ($taxonomies as $taxonomy) { //The data is collected $post_terms = wp_get_object_terms($post->ID,$taxonomy,array(‘fields’=>‘slugs’)); // Data is assigned wp_set_object_terms($draft_id,$post_terms,$taxonomy,false); }$post_meta = get_post_meta($id); fore
ach($post_meta as $key=&gt;$val) {</code></pre>if($key==‘_wp_old_slug’){continue;}
$value=addslashes($val[0]);

//The meta content is inserted into the draft.
add_post_meta($draft_id,$key,$value);
}
return array(‘draft_id’=>$draft_id,‘post’=>$post);
}
else wp_die(‘Error creating draft content.’);
} else wp_die(‘Error creating duplicate. Original content not found’);

}


The third and final function is the one that does the whole process. Check if the user has pressed the “Duplicate” button, and if so, run the function that creates the eraser. If the process was successful, the user will be redirected to the edit screen of this new draft.

/*FUNCTION 3: Finally the duplicate draft is processed once the button is clicked. */function duplicate_content() { global $wpdb; // It checks if the duplicate or clone button has been clicked and if the necessary information is received from the original content. if (!(isset( $_REQUEST[‘post’]) || ( isset($_REQUEST[‘action’]) && $_REQUEST[‘action’]== ‘duplicate_content’ ) ) ) wp_die(‘Error: No reference to the content to be copied’);$id_post = absint( $_REQUEST[‘post’] ) ;//The id received is checked to make sure it is validif($id_post > 0 ){ //Draft is created $draft = create_draft($id_post); //If everything went well, the user is redirected to the draft edit page at the end of the duplicate. if($draft) wp_redirect( admin_url( ‘post.php?action=edit&post=’ . $draft[‘draft_id’] ) ); else wp_die(‘Error creating duplicate content draft. Main content not found’ . $id_post); }else wp_die(‘Error duplicating. Original content not found’ . $id_post); } */After clicking the duplicate button, the action is initiated and the content is duplicated. */ add_action( ‘admin_action_duplicate_content’, ‘duplicate_content’ );

Now you just need to copy it, paste it in and try it out. You can make any changes you want, and if you have any questions, you can leave me a comment.