Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

The way to Duplicate a WordPress Web page or Publish with a single click on?

On this brief publish I’m going to point out you the way to duplicate a WordPress web page or publish with a single click on. Not solely is the strategy actually easy, however it can copy all of the meta date your publish might have (customized fields, featured picture and many others.)

Video: The way to Duplicate a WordPress Web page or Publish and not using a plugin?

The place so as to add the code?

Add a snippet proven right here under to your youngster theme’s features.php file or higher but, use a snippet supervisor like Code Snippets or WpCodeBox (my favourite).

WpCodeBox is my favourite code snippets supervisor for WordPress. It is a premium plugin and in the event you’re , then seize WPCodeBox with a pleasant 20% low cost right here (SAVE 20% Coupon WPSH20).

The way to Duplicate a WordPress Web page or Publish with a single click on?

Subsequent, simply seize the code right here under and it’ll add a “Duplicate” hyperlink inside your fast hyperlinks. See the screenshot.

How to Duplicate a WordPress Page or Post with a single click

For those who click on this hyperlink then:

  • Duplicate of the publish will probably be created
  • Standing of the publish is “Draft”
  • You can be redirected to the publish modifying web page

So, with a view to make it work, simply use this code right here under.

<span position="button" tabindex="0" data-code="// Duplicate a WordPress Web page or Publish with a Single Click on

add_filter("post_row_actions", "wpsh_add_duplicate_link", 10, 2);
add_filter("page_row_actions", "wpsh_add_duplicate_link", 10, 2); // add the hyperlink to pages too

operate wpsh_duplicate_post_as_draft()
{
if (!current_user_can("edit_posts")) {
return;
}
if (
!isset($_GET["duplicate_nonce"]) ||
!wp_verify_nonce($_GET["duplicate_nonce"], basename(__FILE__))
) {
return;
}
world $wpdb;
if (
!(
isset($_GET["post"]) ||
isset($_POST["post"]) ||
(isset($_REQUEST["action"]) &&
"wpsh_duplicate_post_as_draft" == $_REQUEST["action"])
)
) {
wp_die("No publish to duplicate has been provided!");
}
// This on right here will get the unique publish id and publish all the unique publish knowledge
$post_id = isset($_GET["post"])
? absint($_GET["post"])
: absint($_POST["post"]);
$publish = get_post($post_id);

// In case you don't need present consumer to be the brand new publish creator, then change this line to this: $new_post_author = $post->post_author;
$current_user = wp_get_current_user();
$new_post_author = $current_user->ID;

// If publish knowledge exists, create the publish duplicate

if (isset($publish) && $publish != null) {

$args = [
"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,
];

$new_post_id = wp_insert_post($args);

// Get all present publish phrases advert set them to the brand new publish draft

$taxonomies = get_object_taxonomies($post->post_type);
foreach ($taxonomies as $taxonomy) {
$post_terms = wp_get_object_terms($post_id, $taxonomy, [
"fields" => "slugs",
]);
wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false);
}

// Duplicate all publish meta

$post_meta_infos = $wpdb->get_results(
"SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id"
);
if (depend($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") {
proceed;
}
$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->question($sql_query);
}

// Redirect to the edit publish display screen for the brand new draft
wp_safe_redirect(
admin_url("publish.php?motion=edit&publish=" . $new_post_id)
);
exit();
} else {
wp_die(
"Publish creation failed, couldn’t discover authentic publish: " . $post_id
);
}
}
add_action(
"admin_action_wpsh_duplicate_post_as_draft",
"wpsh_duplicate_post_as_draft"
);

// Add the "Duplicate" hyperlink to motion record for post_row_actions

operate wpsh_add_duplicate_link($actions, $publish)
{
if (current_user_can("edit_posts")) {
$actions["duplicate"] =
'<a href="' .
wp_nonce_url(
"admin.php?motion=wpsh_duplicate_post_as_draft&publish=" . $post->ID,
basename(__FILE__),
"duplicate_nonce"
) .
'" title="Duplicate this merchandise" rel="permalink">Duplicate

// Duplicate a WordPress Web page or Publish with a Single Click on

add_filter("post_row_actions", "wpsh_add_duplicate_link", 10, 2);
add_filter("page_row_actions", "wpsh_add_duplicate_link", 10, 2); // add the hyperlink to pages too

operate wpsh_duplicate_post_as_draft()
{
    if (!current_user_can("edit_posts")) {
        return;
    }
    if (
        !isset($_GET["duplicate_nonce"]) ||
        !wp_verify_nonce($_GET["duplicate_nonce"], basename(__FILE__))
    ) {
        return;
    }
    world $wpdb; 
    if (
        !(
            isset($_GET["post"]) ||
            isset($_POST["post"]) ||
            (isset($_REQUEST["action"]) &&
                "wpsh_duplicate_post_as_draft" == $_REQUEST["action"])
        )
    ) {
        wp_die("No publish to duplicate has been provided!");
    }
    // This on right here will get the unique publish id and publish all the unique publish knowledge
    $post_id = isset($_GET["post"])
        ? absint($_GET["post"])
        : absint($_POST["post"]);
   		 $publish = get_post($post_id);
  
  // In case you don't need present consumer to be the brand new publish creator, then change this line to this: $new_post_author = $post->post_author;
    $current_user = wp_get_current_user();
    $new_post_author = $current_user->ID; 

    // If publish knowledge exists, create the publish duplicate

    if (isset($publish) && $publish != null) {

        $args = [
            "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,
        ];

        $new_post_id = wp_insert_post($args);

        // Get all present publish phrases advert set them to the brand new publish draft

        $taxonomies = get_object_taxonomies($publish->post_type); 
        foreach ($taxonomies as $taxonomy) {
            $post_terms = wp_get_object_terms($post_id, $taxonomy, [
                "fields" => "slugs",
            ]);
            wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false);
        }

        // Duplicate all publish meta
        
        $post_meta_infos = $wpdb->get_results(
            "SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id"
        );
        if (depend($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") {
                    proceed;
                }
                $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->question($sql_query);
        }

        // Redirect to the edit publish display screen for the brand new draft
        wp_safe_redirect(
            admin_url("publish.php?motion=edit&publish=" . $new_post_id)
        ); 
        exit();
    } else {
        wp_die(
            "Publish creation failed, couldn't discover authentic publish: " . $post_id
        );
    }
}
add_action(
    "admin_action_wpsh_duplicate_post_as_draft",
    "wpsh_duplicate_post_as_draft"
);

// Add the "Duplicate" hyperlink to motion record for post_row_actions

operate wpsh_add_duplicate_link($actions, $publish)
{
    if (current_user_can("edit_posts")) {
        $actions["duplicate"] =
            '<a href="' .
            wp_nonce_url(
                "admin.php?motion=wpsh_duplicate_post_as_draft&publish=" . $publish->ID,
                basename(__FILE__),
                "duplicate_nonce"
            ) .
            '" title="Duplicate this merchandise" rel="permalink">Duplicate</a>';
    }
    return $actions;
}

After including the code simply go tou your publish, pager or customized publish varieties and press on a “Duplicate” hyperlink and you’ve got a pleasant clone of your website with the standing “Draft”.

The way to Duplicate a WordPress Web page or Publish with a plugin?

In case the earlier technique appears tough for you, you then even have another choice. That’s, you may duplicate a WordPress web page or publish with the assistance of a plugin.

  1. Set up a plugin referred to as “Yoast Duplicate publish”.
  2. Subsequent go to Settings >> Duplicate publish and check out the settings (screenshot under)
  3. When every thing is about up simply go to the pages or posts and use “Clone” hyperlink
The way to Duplicate a WordPress Web page or Publish with a single click on?

Associated WordPress hacks

  • The way to Disguise WordPress Admin Notifications

  • The way to create customized fields in WordPress and not using a plugin?

  • The way to Show Woocommerce Cost Strategies Conditionally? (14 hacks)

  • The way to Customise Woocommerce Inventory Standing? (17 hacks)

  • The way to Add Customized Endpoints in WooCommerce?

  • The way to add and clone consumer roles in WordPress?

  • The way to restore WordPress basic widgets?

  • The way to Add Customized Admin Menu Objects in WordPress?

  • The way to Take away WordPress Admin Menu Objects for Particular Person Roles?

  • The way to Clear & Take away Divi Shortcodes When Altering Your Theme?

  • The way to Create Customized WordPress Admin Dashboard in your prospects?

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart