PHP snippet · Admin & Dashboard

Duplicate posts and pages

Adds a Duplicate link to the row actions on posts, pages, and custom post types. Copies content, custom fields, and terms into a fresh draft.

About this php snippet

Adds a Duplicate action to the row hover menu in Posts and Pages. The copy is created as a draft, titled with a copy suffix, owned by whoever clicked, and you land straight in the editor on it.

Custom fields and taxonomy terms come across, which is what makes this useful with a page builder. An Elementor or Gutenberg layout lives in post meta and post content, so the duplicate is a real working copy you can start editing, not an empty shell with the right title.

What it does

  • Adds a Duplicate link to the row actions on posts, pages, and any custom post type
  • Copies the title, content, excerpt, parent, menu order, every custom field, and every taxonomy term
  • Creates the copy as a draft owned by the person who clicked, then opens it in the editor

Good to know

  • The action is nonce-checked and gated on edit rights for the item being copied, so it cannot be fired by a crafted link
  • The two edit-lock meta keys are skipped on purpose. Copying them makes the new draft claim that somebody else already has it open.
  • Meta values are unserialized before being written, so a stored array is saved as an array rather than as a string of itself. Get that wrong and a duplicated Elementor page opens broken.
  • The copy is always a draft, so nothing goes live by accident

More php snippets