High Performance
Optimized for both client and server-side rendering with minimal overhead. Achieve 947 blocks/ms processing speed with built-in SSR optimizations.
🎉 v1.0.0 STABLE RELEASE NOW AVAILABLE! A powerful utility for converting WordPress block data to framework-agnostic HTML with client-side hydration support.
WP Block to HTML v1.0.0 is now live on NPM! Install it today and start building faster headless WordPress applications.
npm install wp-block-to-html
WP Block to HTML is a production-ready JavaScript library that converts WordPress block data into clean, framework-agnostic HTML. It bridges the gap between WordPress as a content management system and modern frontend applications built with frameworks like React, Vue, Next.js, or any other technology.
import { convertBlocks } from 'wp-block-to-html';
// WordPress blocks data
const blocks = [
{
blockName: 'core/paragraph',
attrs: { content: 'Hello World', align: 'center' },
innerBlocks: []
}
];
// Convert to HTML
const html = convertBlocks(blocks);
console.log(html); // <p class="has-text-align-center">Hello World</p>
The first stable release introduces powerful client-side hydration capabilities for SSR scenarios:
import { HydrationManager } from 'wp-block-to-html/hydration';
// Progressive hydration with multiple strategies
const hydrationManager = new HydrationManager({
strategy: 'viewport', // viewport, interaction, idle, immediate
rootSelector: '#app'
});
// Hydrate specific blocks
await hydrationManager.hydrateBlock('block-id-123');
// Batch hydration
await hydrationManager.hydrateAll();
Easily integrate with popular JavaScript frameworks:
// React Integration
import { createReactComponent } from 'wp-block-to-html/react';
const BlockComponent = createReactComponent(blocks, {
cssFramework: 'tailwind',
hydration: { strategy: 'viewport' }
});
// Vue Integration
import { createVueComponent } from 'wp-block-to-html/vue';
const BlockComponent = createVueComponent(blocks, {
cssFramework: 'bootstrap',
hydration: { strategy: 'interaction' }
});
Generate HTML with classes from your preferred CSS framework:
// Using Tailwind CSS
const html = convertBlocks(blocks, {
cssFramework: 'tailwind'
});
// Using Bootstrap
const html = convertBlocks(blocks, {
cssFramework: 'bootstrap'
});
// Using custom class mappings
const html = convertBlocks(blocks, {
cssFramework: 'custom',
customClassMap
});
Optimize your content for better performance metrics:
// Apply SSR optimizations
const html = convertBlocks(blocks, {
ssrOptions: {
enabled: true,
optimizationLevel: 'maximum',
lazyLoadMedia: true
},
hydration: {
strategy: 'progressive',
priorityBlocks: ['core/button', 'core/gallery']
}
});
# Install the stable release
npm install wp-block-to-html
# Or using yarn
yarn add wp-block-to-html
# Or using pnpm
pnpm add wp-block-to-html
WP Block to HTML is licensed under the MIT License.