{"id":782,"date":"2020-06-12T21:05:35","date_gmt":"2020-06-12T21:05:35","guid":{"rendered":"https:\/\/carrousel.studio\/?p=782"},"modified":"2020-08-21T16:13:34","modified_gmt":"2020-08-21T16:13:34","slug":"acf-gutenberg-blocks","status":"publish","type":"post","link":"https:\/\/carrousel.studio\/en\/acf-gutenberg-blocks\/","title":{"rendered":"Introduction to ACF Gutenberg Blocks"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">ACF Gutenberg implementation for beginners.<\/h2>\n\n\n\n<p>This article assumes that you are somewhat familiar with Gutenberg blocks and Advanced Custom Fields.<\/p>\n\n\n\n<p>Using Gutenberg blocks, editing a WordPress site has become the new way to go.<br>These blocks gives bloggers the ultimate tool to create with ease of use any piece of content<\/p>\n\n\n\n<div class=\"wp-block-media-text has-media-on-the-right is-stacked-on-mobile\" style=\"grid-template-columns:auto 30%\"><figure class=\"wp-block-media-text__media\"><img loading=\"lazy\" decoding=\"async\" width=\"278\" height=\"300\" src=\"https:\/\/carrousel.studio\/wp-content\/uploads\/2020\/06\/guttenberg-blocks-most-used-278x300.png\" alt=\"\" class=\"wp-image-784\" srcset=\"https:\/\/carrousel.studio\/wp-content\/uploads\/2020\/06\/guttenberg-blocks-most-used-278x300.png 278w, https:\/\/carrousel.studio\/wp-content\/uploads\/2020\/06\/guttenberg-blocks-most-used-768x829.png 768w, https:\/\/carrousel.studio\/wp-content\/uploads\/2020\/06\/guttenberg-blocks-most-used.png 802w\" sizes=\"auto, (max-width: 278px) 100vw, 278px\" \/><\/figure><div class=\"wp-block-media-text__content\">\n<p class=\"has-medium-font-size\">Here is what the default Gutenberg tool selector looks like.<br><br>And now, with ACF, you can now add your custom made blocks that serves a specific purpose.<\/p>\n<\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Supercharging your Gutenberg blocks with ACF.<\/h2>\n\n\n\n<p>Here are the primary steps for you to add new custom fields to your Gutenberg toolset.<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Register your new ACF block<\/li><li>Create your ACF field group<\/li><li>Build the block output of how it will appear<\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">1. Register your new ACF block<\/h3>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<p class=\"has-text-align-left\">Basic code sample to register the acf block.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<pre class=\"wp-block-code\"><code>add_action('acf\/init', 'my_acf_init_block_types');\nfunction my_acf_init_block_types() {\n\n    \/\/ Check function exists.\n    if( function_exists('acf_register_block_type') ) {\n\n        \/\/ register a testimonial block.\n        acf_register_block_type(array(\n            'name'              => 'testimonial',\n            'title'             => __('Testimonial'),\n            'description'       => __('A custom testimonial block.'),\n            'render_template'   => 'template-parts\/blocks\/testimonial\/testimonial.php',\n            'category'          => 'formatting',\n            'icon'              => 'admin-comments',\n            'keywords'          => array( 'testimonial', 'quote' ),\n        ));\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><\/h2>\n\n\n\n<p><\/p>\n<\/div>\n<\/div>\n\n\n\n<h3 class=\"wp-block-heading\">2. Create your ACF field group<\/h3>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<p>Add every ACF elements you which to be available in your custom block.<\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"545\" src=\"https:\/\/carrousel.studio\/wp-content\/uploads\/2020\/06\/acf-gutenberg-group-1024x545.png\" alt=\"\" class=\"wp-image-804\" srcset=\"https:\/\/carrousel.studio\/wp-content\/uploads\/2020\/06\/acf-gutenberg-group-1024x545.png 1024w, https:\/\/carrousel.studio\/wp-content\/uploads\/2020\/06\/acf-gutenberg-group-300x160.png 300w, https:\/\/carrousel.studio\/wp-content\/uploads\/2020\/06\/acf-gutenberg-group-768x409.png 768w, https:\/\/carrousel.studio\/wp-content\/uploads\/2020\/06\/acf-gutenberg-group-1536x817.png 1536w, https:\/\/carrousel.studio\/wp-content\/uploads\/2020\/06\/acf-gutenberg-group.png 1560w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n<\/div>\n\n\n\n<h3 class=\"wp-block-heading\">3. Build the block output of how it will appear<\/h3>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<p>For this step, make sure to create a file with the same name defined in step 1.<\/p>\n\n\n\n<p><strong>template-parts\/blocks\/testimonial\/testimonial.php<\/strong><\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<pre class=\"wp-block-code\"><code>&lt;?php\n\n\/**\n * Testimonial Block Template.\n *\n * @param   array $block The block settings and attributes.\n * @param   string $content The block inner HTML (empty).\n * @param   bool $is_preview True during AJAX preview.\n * @param   (int|string) $post_id The post ID this block is saved to.\n *\/\n\n\/\/ Create id attribute allowing for custom \"anchor\" value.\n$id = 'testimonial-' . $block&#91;'id'];\nif( !empty($block&#91;'anchor']) ) {\n    $id = $block&#91;'anchor'];\n}\n\n\/\/ Create class attribute allowing for custom \"className\" and \"align\" values.\n$className = 'testimonial';\nif( !empty($block&#91;'className']) ) {\n    $className .= ' ' . $block&#91;'className'];\n}\nif( !empty($block&#91;'align']) ) {\n    $className .= ' align' . $block&#91;'align'];\n}\n\n\/\/ Load values and assign defaults.\n$text = get_field('testimonial') ?: 'Your testimonial here...';\n$author = get_field('author') ?: 'Author name';\n$role = get_field('role') ?: 'Author role';\n$image = get_field('image') ?: 295;\n$background_color = get_field('background_color');\n$text_color = get_field('text_color');\n\n?>\n&lt;div id=\"&lt;?php echo esc_attr($id); ?>\" class=\"&lt;?php echo esc_attr($className); ?>\">\n    &lt;blockquote class=\"testimonial-blockquote\">\n        &lt;span class=\"testimonial-text\">&lt;?php echo $text; ?>&lt;\/span>\n        &lt;span class=\"testimonial-author\">&lt;?php echo $author; ?>&lt;\/span>\n        &lt;span class=\"testimonial-role\">&lt;?php echo $role; ?>&lt;\/span>\n    &lt;\/blockquote>\n    &lt;div class=\"testimonial-image\">\n        &lt;?php echo wp_get_attachment_image( $image, 'full' ); ?>\n    &lt;\/div>\n    &lt;style type=\"text\/css\">\n        #&lt;?php echo $id; ?> {\n            background: &lt;?php echo $background_color; ?>;\n            color: &lt;?php echo $text_color; ?>;\n        }\n    &lt;\/style>\n&lt;\/div><\/code><\/pre>\n<\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Fun facts<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>The posts of this blog uses ACF Gutenberg blocks.<\/li><li><strong>Gutenberg<\/strong>&nbsp;(\/\u02c8\u0261u\u02d0t\u0259nb\u025c\u02d0r\u0261\/; c. 1400 \u2013 February 3, 1468) was a German goldsmith, inventor, printer, and publisher who introduced printing to Europe with the printing press. And WordPress serves as a modern press system for present writers.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">References<\/h2>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<ul><li><a href=\"https:\/\/www.advancedcustomfields.com\/resources\/blocks\/\" target=\"_blank\" rel=\"noreferrer noopener\">ACF | Blocks<\/a><\/li><li><a href=\"https:\/\/www.advancedcustomfields.com\/blog\/acf-5-8-introducing-acf-blocks-for-gutenberg\/\" target=\"_blank\" rel=\"noreferrer noopener\">ACF | ACF 5.8 &#8211; Introducing ACF Blocks for Gutenberg<\/a><\/li><li><a href=\"https:\/\/pantheon.io\/blog\/building-gutenberg-blocks-advanced-custom-fields\" target=\"_blank\" rel=\"noreferrer noopener\">Building Gutenberg Blocks with ACF<\/a><\/li><li><a href=\"https:\/\/www.youtube.com\/watch?v=vxxHoEqxjKE\" target=\"_blank\" rel=\"noreferrer noopener\">How To Make A Gutenberg Block With Advanced Custom Fields &#8211; For Beginners (youtube)<\/a><\/li><li><a href=\"https:\/\/www.youtube.com\/watch?v=s6qomMzP0BU\" target=\"_blank\" rel=\"noreferrer noopener\">ACF Blocks | Gutenberg (youtube)<\/a><\/li><\/ul>\n<\/div><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to make a custom Gutenburg block with Advanced Custom Fields (ACF)<\/p>\n","protected":false},"author":1,"featured_media":809,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[14],"tags":[],"class_list":["post-782","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-development"],"acf":[],"_links":{"self":[{"href":"https:\/\/carrousel.studio\/en\/wp-json\/wp\/v2\/posts\/782","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/carrousel.studio\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/carrousel.studio\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/carrousel.studio\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/carrousel.studio\/en\/wp-json\/wp\/v2\/comments?post=782"}],"version-history":[{"count":34,"href":"https:\/\/carrousel.studio\/en\/wp-json\/wp\/v2\/posts\/782\/revisions"}],"predecessor-version":[{"id":1054,"href":"https:\/\/carrousel.studio\/en\/wp-json\/wp\/v2\/posts\/782\/revisions\/1054"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/carrousel.studio\/en\/wp-json\/wp\/v2\/media\/809"}],"wp:attachment":[{"href":"https:\/\/carrousel.studio\/en\/wp-json\/wp\/v2\/media?parent=782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/carrousel.studio\/en\/wp-json\/wp\/v2\/categories?post=782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/carrousel.studio\/en\/wp-json\/wp\/v2\/tags?post=782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}