1. Home
  2. WordPress
  3. Custom Block Development
  4. basic

basic

চমৎকার! তুমি চাচ্ছো এমন একটি ✅ ফুল ওয়ার্কিং WordPress প্লাগইন:

  • ২টি Gutenberg ব্লক থাকবে
  • TailwindCSS CDN ব্যবহার করবে (Editor + Frontend)
  • কোনও import স্টেটমেন্ট থাকবে না (কাজ করবে Vanilla JS দিয়ে)
  • কোনো build system লাগবে না (no Webpack, no package.json)

✅ ফোল্ডার স্ট্রাকচার (Ready-to-Copy)

custom-blocks-plugin/
├── plugin.php
├── block-one/
   ├── index.js
   └── style.css
├── block-two/
   ├── index.js
   └── style.css

plugin.php (মূল প্লাগইন ফাইল)

<?php
/**
 * Plugin Name: Custom Blocks Plugin
 * Description: A plugin with two custom Gutenberg blocks and TailwindCSS support.
 * Version: 1.0
 * Author: Your Name
 */

function cbp_enqueue_tailwind() {
    // TailwindCSS for frontend
    wp_enqueue_style('cbp-tailwind', 'https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css', [], null);
}
add_action('wp_enqueue_scripts', 'cbp_enqueue_tailwind');

function cbp_register_blocks() {
    // TailwindCSS for editor
    wp_enqueue_style('cbp-editor-tailwind', 'https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css', [], null);

    // BLOCK ONE
    wp_register_script(
        'cbp-block-one-js',
        plugins_url('block-one/index.js', __FILE__),
        ['wp-blocks', 'wp-element'],
        filemtime(plugin_dir_path(__FILE__) . 'block-one/index.js'),
        true
    );
    wp_register_style(
        'cbp-block-one-css',
        plugins_url('block-one/style.css', __FILE__),
        [],
        filemtime(plugin_dir_path(__FILE__) . 'block-one/style.css')
    );
    register_block_type('cbp/block-one', [
        'editor_script' => 'cbp-block-one-js',
        'editor_style'  => 'cbp-block-one-css',
        'style'         => 'cbp-block-one-css',
    ]);

    // BLOCK TWO
    wp_register_script(
        'cbp-block-two-js',
        plugins_url('block-two/index.js', __FILE__),
        ['wp-blocks', 'wp-element'],
        filemtime(plugin_dir_path(__FILE__) . 'block-two/index.js'),
        true
    );
    wp_register_style(
        'cbp-block-two-css',
        plugins_url('block-two/style.css', __FILE__),
        [],
        filemtime(plugin_dir_path(__FILE__) . 'block-two/style.css')
    );
    register_block_type('cbp/block-two', [
        'editor_script' => 'cbp-block-two-js',
        'editor_style'  => 'cbp-block-two-css',
        'style'         => 'cbp-block-two-css',
    ]);
}
add_action('init', 'cbp_register_blocks');

block-one/index.js

(function (blocks, element) {
    var el = element.createElement;

    blocks.registerBlockType('cbp/block-one', {
        title: 'Block One',
        icon: 'smiley',
        category: 'design',
        edit: function () {
            return el('div', { className: 'bg-blue-200 p-4 rounded' },
                el('h2', { className: 'text-xl font-bold' }, 'Block One (Editor)')
            );
        },
        save: function () {
            return el('div', { className: 'bg-blue-200 p-4 rounded' },
                el('h2', { className: 'text-xl font-bold' }, 'Block One (Frontend)')
            );
        }
    });
})(window.wp.blocks, window.wp.element);

block-one/style.css

/* Block One Styles */
.wp-block-cbp-block-one {
    margin: 1rem 0;
}

block-two/index.js

(function (blocks, element) {
    var el = element.createElement;

    blocks.registerBlockType('cbp/block-two', {
        title: 'Block Two',
        icon: 'star-filled',
        category: 'design',
        edit: function () {
            return el('div', { className: 'bg-green-200 p-4 rounded' },
                el('p', { className: 'text-lg' }, 'Block Two (Editor)')
            );
        },
        save: function () {
            return el('div', { className: 'bg-green-200 p-4 rounded' },
                el('p', { className: 'text-lg' }, 'Block Two (Frontend)')
            );
        }
    });
})(window.wp.blocks, window.wp.element);

block-two/style.css

/* Block Two Styles */
.wp-block-cbp-block-two {
    margin: 1rem 0;
}

✅ ব্যবহারবিধি

  1. ফোল্ডারটাকে wp-content/plugins/custom-blocks-plugin/ তে রাখো
  2. Admin Panel → Plugins → Custom Blocks Plugin → Activate করো
  3. Gutenberg Editor এ গিয়ে Block One এবং Block Two খুঁজে পাবে “Design” ক্যাটাগরিতে
  4. Tailwind CSS editor ও frontend দুই জায়গায় কাজ করবে

✅ পরবর্তী ধাপে চাইলে

  • RichText ব্যবহার করে text editable বানাতে পারো
  • InspectorControls ব্যবহার করে ব্লক সেটিংস অ্যাড করতে পারো
  • Tailwind JIT + build system চাইলে npm setup সহ boilerplate দিতেও পারি

তুমি চাইলে আমি এই ফোল্ডারটাকে .zip ফাইল আকারেও দিতে পারি।
তুমি কি .zip ফাইল চাও?

How can we help?