Developer Documentation

Quick Overview

Block Editor Filters

Customize the aspect ratio dropdown options shown in the block editor sidebar.

Use Case: Replace generic ratios with client-friendly labels like “Product Image” or “Hero Banner”

Pro Tip: Use Image Dimensions

Don’t know the aspect ratio? Just use your image’s actual width and height!

Example: Image is 1200px × 800px → use value 1200/800

Important: Existing Blocks Behavior

Old values persist: Query Loops Blocks with Masonry with previously selected aspect ratios keep those values, even if removed from filter options.

Frontend continues working: CSS is generated with stored values regardless of current filter options.

Editor UI: Dropdown may appear blank if stored value doesn’t match any current option.

Values only change: When user manually selects a new option from the dropdown.

Plugin’s Default options for reference


Option 1: JavaScript (Recommended)

Add this code to your existing block editor JavaScript file. If you already have a JS file enqueued via enqueue_block_editor_assets, use that.

wp.hooks.addFilter(
    'ph_qlm.aspectRatioOptions',
    'my-theme/ratios',
    (options) => [
        { label: 'Hero Image', value: '5/3' },
        { label: 'Product Card', value: '4/5' },
        { label: 'Thumbnail', value: '1/1' }
    ]
);

Option 2: Create New JavaScript File

Don’t have a block editor JS file? Create one and enqueue it:

1. Create file in your theme:

wp.hooks.addFilter(
    'ph_qlm.aspectRatioOptions',
    'my-theme/ratios',
    (options) => [
        { label: 'Hero Image', value: '5/3' },
        { label: 'Product Card', value: '4/5' },
        { label: 'Thumbnail', value: '1/1' }
    ]
);

2. Enqueue in functions.php:

function my_theme_enqueue_editor_assets() {
    wp_enqueue_script(
        'my-theme-editor-customizations',
        get_template_directory_uri() . '/js/editor-customizations.js',
        ['wp-hooks', 'ph-qlm-editor-extensions'],
        wp_get_theme()->get('Version'),
        true
    );
}
add_action(
    'enqueue_block_editor_assets',
    'my_theme_enqueue_editor_assets'
);

Option 3: PHP Only (Simple)

Quick approach using inline script. Less maintainable but works for simple customizations.

function my_custom_ratios() {
    $script = "
    wp.hooks.addFilter(
        'ph_qlm.aspectRatioOptions',
        'my-theme/ratios',
        function(options) {
            return [
                { label: 'Hero Image', value: '5/3' },
                { label: 'Product Card', value: '4/5' },
                { label: 'Thumbnail', value: '1/1' }
            ];
        }
    );
    ";

    wp_add_inline_script(
        'ph-qlm-editor-extensions',
        $script,
        'after'
    );
}
add_action(
    'enqueue_block_editor_assets',
    'my_custom_ratios',
    20
);

Control the maximum number of selector position slots available in the editor.

Default6 positions (1st, 2nd, 3rd, 4th, 5th, 6th)

Why Limit or Extend number of Positions?

  • Prevent client confusion with too few or too many options
  • Hero layouts (first 3 posts only)
  • Fixed pattern designs
  • Simplified UI for content editors

Use Case: News site with hero layout – only first 3 posts need custom aspect ratios


Option 1: JavaScript (Recommended)

Add this code to your existing block editor JavaScript file. If you already have a JS file enqueued via enqueue_block_editor_assets, use that.

wp.hooks.addFilter(
    'ph_qlm.maxPositions',
    'my-theme/positions',
    (max) => 3 // Limit to 3 position slots
);

Option 2: Create New JavaScript File

Don’t have a block editor JS file? Create one and enqueue it:

1. Create file in your theme:

wp.hooks.addFilter(
    'ph_qlm.maxPositions',
    'my-theme/positions',
    (max) => 3
);

2. Enqueue in functions.php:

function my_theme_enqueue_editor_assets() {
    wp_enqueue_script(
        'my-theme-editor-customizations',
        get_template_directory_uri() . '/js/editor-customizations.js',
        ['wp-hooks', 'ph-qlm-editor-extensions'],
        wp_get_theme()->get('Version'),
        true
    );
}
add_action(
    'enqueue_block_editor_assets',
    'my_theme_enqueue_editor_assets'
);

Option 3: PHP Only (Simple)

Quick approach using inline script. Less maintainable but works for simple customizations.

function limit_positions() {
    $script = "
    wp.hooks.addFilter(
        'ph_qlm.maxPositions',
        'my-theme/positions',
        function(max) {
            return 3;
        }
    );
    ";

    wp_add_inline_script(
        'ph-qlm-editor-extensions',
        $script,
        'after'
    );
}
add_action(
    'enqueue_block_editor_assets',
    'limit_positions',
    20
);

Frontend API

Access and control all running masonry instances via window.ph_qlm

Plugin version string

Array of MasonryController instances

Destroy all instances and cleanup

Note: API available after DOMContentLoaded event

Inspect API Structure

console.log(window.ph_qlm);

// Output:
{
  version: '0.1.0',
  instances: [/* MasonryController[] */],
  destroyAll: Function
}

Individual Instance Control

// Access first instance
const instance = window.ph_qlm.instances[0];

// Destroy instance
instance.destroy();

// Get Masonry instance
const masonry = instance.getInstance();

Batch Operations

// Destroy everything
window.ph_qlm.destroyAll();

Real-World Examples

Photography Portfolio

Custom aspect ratios for different photography styles

Requirements

  • Hero shot in 5:3 ratio
  • Portrait photos in 4:5
  • Cinematic wide shots
  • Square prints for Instagram

Replace generic options with photography-specific terminology

wp.hooks.addFilter(
    'ph_qlm.aspectRatioOptions',
    'photo-site/ratios',
    (options) => [
        {
            label: 'Hero Shot (5:3)',
            value: '5/3'
        },
        {
            label: 'Portrait (4:5)',
            value: '4/5'
        },
        {
            label: 'Cinematic (2.35:1)',
            value: '2.35/1'
        },
        {
            label: 'Square Print',
            value: '1/1'
        }
    ]
);

📰

News Site Hero Layout

Fixed hero layout with limited slots

Layout Structure

  • Position 1: Hero story (16:9)
  • Position 2-3: Featured articles (4:3)
  • Remaining: Standard posts
  • Max 3 position slots needed

Limit positions to prevent unnecessary complexity

//Limit to 3 positions
wp.hooks.addFilter(
    'ph_qlm.maxPositions',
    'news-site/positions',
    () => 3
);

// News-specific ratios
wp.hooks.addFilter(
    'ph_qlm.aspectRatioOptions',
    'news-site/ratios',
    (options) => [
        {
            label: 'Hero Story',
            value: '16/9'
        },
        {
            label: 'Featured Article',
            value: '4/3'
        },
        {
            label: 'Standard Post',
            value: '3/4'
        }
    ]
);

AJAX Content Loading

Automatic detection with MutationObserver

Masonry uses MutationObserver to automatically detect when posts are added or removed from the DOM. Your AJAX implementations will work automatically without any extra code.

Works Automatically With

  • Load more buttons
  • Infinite scroll
  • WordPress Query Loop pagination
  • Filter/search results
  • Any dynamic content updates

How It Works

The plugin watches the masonry container for changes. When .wp-block-post elements are added or removed, masonry automatically re-calculates the layout.

Manual Control: The API is still available for edge cases where you need explicit control over layout timing.

Automatic (Recommended)

(Example of how your AJAX code might look like)

// Just update the DOM - masonry handles the rest!
fetch('/api/posts')
  .then(response => response.json())
  .then(data => {
    // Update DOM
    updatePostsDOM(data);

    // That's it! MutationObserver handles re-layout
  });

// Load more button - no manual layoutAll() needed
loadMoreBtn.addEventListener('click', async () => {
  const newPosts = await fetchPosts();
  container.append(newPosts);

  // Masonry automatically detects new posts
});

Manual Control (Edge Cases)

For rare cases where you need explicit timing control

// Force immediate re-layout
window.ph_qlm.layoutAll();

// Or control specific instance
window.ph_qlm.instances[0].layout();

Technical Reference