Skip to content
  • Quick Ref
  • Contact
  • About
wpcanyon.com

wpcanyon.com

Tag: Editor

Create and manage reusable blocks (patterns)

Posted on August 19, 2025 By Admin No Comments on Create and manage reusable blocks (patterns)

Create and Manage Reusable Blocks (Patterns) in WordPress

If you frequently use the same content layout or design elements in WordPress, creating reusable blocks (also known as block patterns) can save you time and maintain consistency. This tutorial explains how to create, manage, and use reusable blocks in WordPress quickly and efficiently.

Quick Fix: How to Create Reusable Blocks in WordPress

  1. Open the WordPress block editor (Gutenberg) on any post or page.
  2. Create or select the block(s) you want to reuse.
  3. Click the three-dot menu on the block toolbar and select Add to Reusable Blocks.
  4. Name your reusable block and save it.
  5. To insert the reusable block later, click the + Add Block button, go to the Reusable tab, and select your block.

Why This Happens

WordPress introduced reusable blocks to help users avoid repetitive work by saving blocks or groups of blocks as reusable components. This feature is especially useful for site-wide elements like call-to-action sections, disclaimers, or frequently used layouts. Without reusable blocks, you would have to recreate or copy-paste the same content repeatedly, which is inefficient and error-prone.

Requirements

  • WordPress 5.0 or higher (Gutenberg block editor included by default)
  • Access to the WordPress admin dashboard
  • Basic familiarity with the block editor interface

Step-by-Step: Create and Manage Reusable Blocks in WordPress

1. Create a Reusable Block

  1. Go to Posts > Add New or open an existing post/page.
  2. Add the block(s) you want to reuse. For example, a paragraph, image, or group block.
  3. Click on the block to select it. If you want to reuse multiple blocks, group them first by selecting all and clicking Group from the block toolbar.
  4. Click the three-dot menu icon (More options) on the block toolbar.
  5. Select Add to Reusable Blocks.
  6. Enter a descriptive name for your reusable block and click Save.

2. Insert a Reusable Block

  1. Open any post or page in the block editor.
  2. Click the + Add Block button.
  3. Switch to the Reusable tab.
  4. Select the reusable block you want to insert.

3. Manage Reusable Blocks

  1. In the WordPress admin sidebar, go to Manage All Reusable Blocks by clicking the Reusable tab in the block inserter and then Manage all at the bottom.
  2. Here you can edit, delete, or export reusable blocks.
  3. Editing a reusable block updates all instances of that block across your site.

Code Snippets: Registering Custom Block Patterns Programmatically

If you want to create reusable block patterns programmatically (for developers), add the following code to your theme’s functions.php or a custom plugin:

function mytheme_register_block_patterns() {
    if ( function_exists( 'register_block_pattern' ) ) {
        register_block_pattern(
            'mytheme/two-columns-text-image',
            array(
                'title'       =__( 'Two Columns: Text and Image', 'mytheme' ),
                'description' =_x( 'A two column layout with text on the left and image on the right.', 'Block pattern description', 'mytheme' ),
                'content'     ="
                    
                    

Insert your text here.

" ) ); } } add_action( 'init', 'mytheme_register_block_patterns' );

This registers a reusable block pattern that users can insert from the block inserter under the Patterns tab.

Common Pitfalls When Creating Reusable Blocks

  • Editing a reusable block changes all instances: When you edit a reusable block inside a post, it updates everywhere. To avoid this, convert the reusable block to regular blocks before editing by selecting it and clicking Convert to Regular Blocks.
  • Reusing dynamic content: Reusable blocks store static content. If you want dynamic content (e.g., latest posts), consider using block patterns with dynamic blocks or custom blocks.
  • Deleting reusable blocks: Deleting a reusable block from the management screen will remove it from all posts/pages where it is used.
  • Compatibility: Older WordPress versions (before 5.0) do not support reusable blocks.

Works on

  • Web servers: Apache, Nginx, LiteSpeed
  • Hosting panels: cPanel, Plesk, and others
  • WordPress 5.0+ with Gutenberg block editor enabled
  • Compatible with most modern themes and plugins supporting the block editor

FAQ

Q1: Can I export reusable blocks and use them on another WordPress site?
A1: Yes. Go to Manage All Reusable Blocks, select the block, and use the export option to download a JSON file. Import it on another site via the block editor.
Q2: How do I update a reusable block without affecting existing posts?
A2: Convert the reusable block to regular blocks before editing. This breaks the link and edits only the current instance.
Q3: Can reusable blocks contain multiple blocks?
A3: Yes. You can group multiple blocks and save the group as a reusable block.
Q4: Are reusable blocks the same as
…
Admin & Blocks

Disable Gutenberg for specific post types

Posted on August 19, 2025 By Admin No Comments on Disable Gutenberg for specific post types

Disable Gutenberg for Specific Post Types

If you want to disable the Gutenberg block editor for certain post types in WordPress, this quick guide will show you how. By default, Gutenberg is enabled for all post types that support the editor, but sometimes you need to revert to the classic editor or a custom meta box interface for specific post types. The fix is simple: add a small code snippet to your theme or plugin to disable Gutenberg selectively.

Quick Fix

  1. Identify the post types where you want to disable Gutenberg.
  2. Add a PHP filter to disable Gutenberg for those post types.
  3. Place the code in your theme’s functions.php file or a custom plugin.
  4. Clear caches and test the post editor for the specified post types.

Why This Happens

Gutenberg is WordPress’s default block editor introduced in version 5.0. It automatically activates for all post types that declare support for the editor. However, some custom post types or legacy content require the classic editor or a different editing interface. WordPress does not provide a built-in UI to disable Gutenberg on a per-post-type basis, so developers must use filters to control its activation.

Requirements

  • WordPress 5.0 or higher with Gutenberg enabled.
  • Access to your theme’s functions.php file or ability to create a custom plugin.
  • Basic knowledge of PHP and WordPress hooks.

Step-by-step: Disable Gutenberg for Specific Post Types

  1. Open your theme’s functions.php file or create a custom plugin file.
  2. Insert the following PHP code snippet:
<?php
/**
 * Disable Gutenberg editor for specific post types.
 *
 * @param bool   $is_enabled Whether the editor is enabled.
 * @param string $post_type  The post type being checked.
 * @return bool
 */
function disable_gutenberg_for_post_types( $is_enabled, $post_type ) {
    // List post types to disable Gutenberg for
    $disabled_post_types = array( 'your_post_type', 'another_post_type' );

    if ( in_array( $post_type, $disabled_post_types, true ) ) {
        return false; // Disable Gutenberg
    }

    return $is_enabled; // Keep default behavior for others
}
add_filter( 'use_block_editor_for_post_type', 'disable_gutenberg_for_post_types', 10, 2 );
  1. Replace your_post_type and another_post_type with your actual post type slugs.
  2. Save the file and upload it to your server if editing locally.
  3. Clear any caching plugins or server caches.
  4. Test by editing a post of the specified post types; the classic editor or meta boxes should appear instead of Gutenberg.

Additional Tips

  • If you want to disable Gutenberg for all custom post types, you can modify the code to check if the post type is not ‘post’ or ‘page’.
  • To disable Gutenberg for all post types, return false unconditionally in the filter.

Common Pitfalls

  • Incorrect post type slug: Make sure you use the exact post type slug registered in WordPress.
  • Code placement: Adding the code in the wrong place (e.g., outside PHP tags) will cause errors.
  • Conflicts with plugins: Some plugins override editor settings; test with plugins disabled if issues arise.
  • Caching: Browser or server caching might show the old editor; clear caches after changes.
  • Editor support: This method only works if the post type supports the editor feature.

Works on

  • Web servers: Apache, Nginx, LiteSpeed
  • Control panels: cPanel, Plesk, DirectAdmin
  • WordPress environments with PHP 7.0+ (recommended 7.4+)
  • Any WordPress theme or plugin setup where you can add PHP code

FAQ

Question Answer
Can I disable Gutenberg only for posts but keep it for pages? Yes. Use the code snippet and set $disabled_post_types = array('post'); to disable Gutenberg only for posts.
Will this code affect the REST API? No. This filter only controls the editor interface in the admin area. The REST API remains unaffected.
How do I find the post type slug? You can find it in the post type registration code or by inspecting the URL when editing a post (e.g., post.php?post=123&post_type=your_post_type).
Can I disable Gutenberg for all custom post types automatically? Yes. Modify the function to check if the post type is not ‘post’ or ‘page’ and return false accordingly.
Is there a plugin alternative to this code? Yes, plugins like “Classic Editor” or “Disable Gutenberg” offer UI options to disable Gutenberg per post type without coding.
…
Admin & Blocks

Duplicate a page or post without a plugin

Posted on August 19, 2025 By Admin No Comments on Duplicate a page or post without a plugin

Duplicate a Page or Post Without a Plugin in WordPress

Need to duplicate a page or post in WordPress but want to avoid installing another plugin? This quick guide shows you how to clone any page or post manually by adding a simple code snippet to your theme’s functions.php file. It’s a clean, lightweight solution that keeps your site fast and clutter-free.

Quick Fix: Duplicate a Page or Post Without a Plugin

  1. Access your WordPress theme’s functions.php file via FTP or the theme editor.
  2. Copy and paste the provided duplication function code into functions.php.
  3. Save the file and refresh your WordPress admin dashboard.
  4. Go to the Pages or Posts list, hover over the item you want to duplicate, and click the new “Duplicate” link.
  5. A draft copy of the page or post will be created immediately, ready for editing.

Why This Happens

WordPress does not include a built-in “duplicate” or “clone” feature for pages or posts. Many users rely on plugins to add this functionality, but plugins can add extra overhead and potential security risks. By adding a custom function, you can create a native duplication option that integrates seamlessly with your admin interface without relying on third-party code.

Requirements

  • Basic familiarity with editing WordPress theme files.
  • Access to your site’s functions.php file via FTP, SFTP, or the WordPress theme editor.
  • Administrator privileges in WordPress.
  • Backup your site before making any code changes to avoid accidental data loss.

Step-by-Step: Add Duplicate Page/Post Functionality

  1. Backup your site. Always create a full backup before editing theme files.
  2. Open your theme’s functions.php file. You can do this via FTP or from the WordPress dashboard under Appearance > Theme Editor.
  3. Paste the following code at the end of the functions.php file:
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!');
    }

    // Get the original post id
    $post_id = (isset($_GET['post']) ? absint($_GET['post']) : absint($_POST['post']));
    // Get the original post
    $post = get_post($post_id);

    // Check if post exists
    if (null == $post) {
        wp_die('Post does not exist!');
    }

    // Check user permissions
    if (!current_user_can('edit_posts')) {
        wp_die('You do not have sufficient permissions to duplicate this post.');
    }

    // New post data array
    $new_post = array(
        'post_title'     =$post-post_title . ' (Copy)',
        'post_content'   =$post-post_content,
        'post_status'    ='draft',
        'post_type'      =$post-post_type,
        'post_author'    =wp_get_current_user()-ID,
        'post_excerpt'   =$post-post_excerpt,
        'post_parent'    =$post-post_parent,
        'menu_order'     =$post-menu_order,
        'comment_status' =$post-comment_status,
        'ping_status'    =$post-ping_status,
        'post_password'  =$post-post_password,
        'to_ping'        =$post-to_ping,
        'pinged'         =$post-pinged,
        'post_content_filtered' =$post-post_content_filtered,
        'post_mime_type' =$post-post_mime_type,
        'guid'           ='',
    );

    // Insert the post by wp_insert_post()
    $new_post_id = wp_insert_post($new_post);

    // Copy taxonomies
    $taxonomies = get_object_taxonomies($post-post_type);
    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);
    }

    // Copy post meta
    $post_meta = get_post_meta($post_id);
    foreach ($post_meta as $meta_key =$meta_values) {
        foreach ($meta_values as $meta_value) {
            add_post_meta($new_post_id, $meta_key, maybe_unserialize($meta_value));
        }
    }

    // Redirect to the edit post screen for the new draft
    wp_redirect(admin_url('post.php?action=edit&post=' . $new_post_id));
    exit;
}
add_action('admin_action_rd_duplicate_post_as_draft', 'rd_duplicate_post_as_draft');

function rd_duplicate_post_link($actions, $post) {
    if (current_user_can('edit_posts')) {
        $actions['duplicate'] = '';
    }
    return $actions;
}
add_filter('post_row_actions', 'rd_duplicate_post_link', 10, 2);
add_filter('page_row_actions', 'rd_duplicate_post_link', 10, 2);
  1. Save the functions.php file.
  2. Go to the Pages or Posts list in your WordPress admin. Hover over any item and click the new Duplicate link.
  3. Edit the duplicated draft. The copy will open in the editor as a draft, ready for your changes.

Common Pitfalls

  • Editing the wrong functions.php file: Make sure you edit the active theme’s functions.php. Child themes are recommended to avoid losing changes on updates.
  • Missing user permissions: The duplication function checks if the user can edit posts. If you don’t have sufficient rights, the link won’t appear or duplication will fail.
  • Meta data serialization: The code uses maybe_unserialize() to handle serialized meta values correctly. Avoid modifying this unless you understand serialization.
  • Taxonomies not copied: The code copies all taxonomies assigned to the original post, but custom taxonomies may require additional handling if they have complex relationships.

…
Admin & Blocks

Recent Posts

  • Top WordPress Themes for Blogs in 2025
  • WordPress Admin Panel Trick: Adding ID Field to the Posts Listing
  • Solution previous_posts_link and next_posts_link Not Working
  • Show Top Commentators in WordPress Without a Plugin
  • How to Style Admin Comments in WordPress

Recent Comments

    Archives

    • August 2025

    Categories

    • Admin & Blocks
    • Admin & UI
    • Automation
    • Automation & Plugins
    • Comments
    • Comparisons
    • Database & Revisions
    • Developer Snippets
    • Fixes & Errors
    • Media & Thumbnails
    • Queries & Pagination
    • Security
    • Speed & Security
    • Tips & Tricks
    • WooCommerce How‑tos
    • WordPress Snippets
    • WordPress Themes
    • Terms & Conditions
    • Affiliate Disclosure

    Copyright © 2025 wpcanyon.com.

    Powered by PressBook WordPress theme

    Also by the maker of MySurveyReviews.com