Initializing
Back to Projects
Year2024
DomainFullstack
AccessOpen Source
Complexity0 / 10
PHPWordPressWordPress SnippetNavigationMenu
FullstackArchived

Menu Order Shuffler (WordPress Snippet)

A WordPress snippet that enables menu_order support for all public post types, allowing custom ordering of posts, pages, products, and custom post types via the WordPress admin.

# Menu Order Shuffler (WordPress Snippet)

A lightweight WordPress snippet that enables the native menu ordering functionality across all public post types, including WooCommerce products, allowing custom drag-and-drop ordering through WordPress admin.

Purpose

WordPress by default only allows page ordering. This snippet extends menu ordering to:

  • All custom post types
  • WooCommerce products
  • Custom post types that don't support page-attributes

Implementation

php
// Enable menu_order support for all public post types
add_action('init', function () {
    $post_types = get_post_types(['public' => true], 'names');
    
    foreach ($post_types as $pt) {
        if (!post_type_supports($pt, 'page-attributes') || $pt === 'product') {
            add_post_type_support($pt, 'page-attributes');
        }
    }
});

Usage

  1. Add to theme's functions.php or use with a snippet plugin
  2. Go to any post type list in admin
  3. Use the "Order" column to drag and reorder
  4. Changes reflect on the frontend based on menu_order

Post Types Affected

  • Posts
  • Pages
  • WooCommerce Products
  • Custom Post Types

Additional Features (from full snippet)

  • Column visibility toggle
  • Bulk order reset
  • Custom order display
  • Quick edit support

Architecture Feedback

Spotted a potential optimization or antipattern? Let me know.

Submit a Technical Suggestion