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.

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

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->

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 valid
    if($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.