Skip to content

A simple CLI script to scaffold custom ACF-powered Gutenberg blocks in your WordPress project.

Notifications You must be signed in to change notification settings

valentin-grenier/make-acf-block

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Make ACF Block script

A simple CLI script to scaffold custom ACF-powered Gutenberg blocks in your WordPress project.

๐Ÿ“ฆ Getting Started

  1. Clone the repo
  2. Install dependencies
    npm install
  3. Install ACF Pro: Make sure you have the Advanced Custom Fields Pro plugin installed and activated in your WordPress project.
  4. Add the script to your project: Copy the scripts/make-acf-block.js file to your WordPress theme or plugin directory.

โš™๏ธ Setup

  1. Script location: All the logic lives in scripts/make-acf-block.js.

  2. Add the script in package.json: You can add a script entry in your package.json to make it easier to run:

    {
    	"scripts": {
    		"make-acf-block": "node scripts/make-acf-block.js"
    	}
    }
  3. Register your ACF blocks in functions.php using register_block_type() ACF function.

    // functions.php
    function register_custom_acf_blocks() {
        $block_json_files = glob(get_stylesheet_directory() . '/blocks/*/block.json');
    
        foreach ($block_json_files as $block) {
            register_block_type($block);
        }
    }
    add_action('acf/init', 'register_custom_acf_blocks');

๐Ÿš€ Usage

Run the CLI with the block slug you want to create:

npm run make-acf-block my-block

This will create a new folder blocks/my-block with:

  • block.json
  • my-block.css
  • my-block.js
  • my-block.php

๐Ÿ› ๏ธ Contributing & Issues

If you find a bug or have a feature request, please open an issue on this repo.

  • Fork the project
  • Create your feature branch (git checkout -b feature/your-feature)
  • Commit your changes (git commit -m 'Add some feature')
  • Push to the branch (git push origin feature/your-feature)
  • Open a Pull Request

Made with ๐Ÿ’ป by Valentin Grenier from Studio Val.

About

A simple CLI script to scaffold custom ACF-powered Gutenberg blocks in your WordPress project.

Topics

Resources

Stars

Watchers

Forks