Halloween Sale 15% off Ends in See the plans
PHP

Block Pattern: Plan Comparison Table

Adds a comparison table pattern with a header row and check marks for comparing plans, products or options side by side.

Don’t have WPIDE yet? Install it on your site

Code

add_action( 'init', function () {
    if ( ! function_exists( 'register_block_pattern' ) ) {
        return;
    }

    if ( ! WP_Block_Pattern_Categories_Registry::get_instance()->is_registered( 'wpide-sections' ) ) {
        register_block_pattern_category( 'wpide-sections', array( 'label' => 'Site Sections' ) );
    }

    $rows = array(
        array( 'Websites', '1', '5', 'Unlimited' ),
        array( 'Daily backups', '✔', '✔', '✔' ),
        array( 'Priority support', '—', '✔', '✔' ),
        array( 'White-label reports', '—', '—', '✔' ),
    );

    $body = '';
    foreach ( $rows as $row ) {
        $body .= '<tr><td>' . implode( '</td><td>', $row ) . '</td></tr>';
    }

    $content = '<!-- wp:table {"hasFixedLayout":true} --><figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>Feature</th><th>Starter</th><th>Growth</th><th>Agency</th></tr></thead><tbody>' . $body . '</tbody></table></figure><!-- /wp:table -->';

    register_block_pattern( 'wpide/comparison-table', array(
        'title'       => 'Comparison table: three plans',
        'description' => 'Feature rows compared across three plans.',
        'categories'  => array( 'wpide-sections' ),
        'keywords'    => array( 'comparison', 'table', 'plans', 'features' ),
        'content'     => $content,
    ) );
} );

Notes

Edit cells directly in the table after inserting. Pair it with the "Lined" or "Hover rows" table styles.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.