Hello, I am having a problem using a custom ACF block I have registered in my theme’s editor page.
I have registered the block like this
add_action( 'acf/init', 'hfm_acf_init_blocks' );
function hfm_acf_init_blocks() {
if ( function_exists( 'acf_register_block_type' ) ) {
acf_register_block_type(
array(
'name' => 'episode-metadata',
'title' => 'Episode',
'description' => 'Spotify/Google Podacast links for an episode/podcast',
'render_template' => 'block_templates/episode-metadata.php',
'category' => 'text',
'icon' => 'admin-comments',
'api_version' => 2,
'keywords' => array( 'episodes', 'podcasts' ),
'mode' => 'preview',
'supports' => array(
'jsx' => true,
'color' => array(
'text' => true,
'background' => false,
),
'align_text' => true,
),
)
);
}
}
and in my template file this is the html I am rendering for this block
<?php
$align = isset($block['align_text']) ? $block['align_text'] : 'left';
$textcolor = isset($block['textColor']) ? $block['textColor'] : 'inherit';
if (substr($textcolor, 0, 1) !== '#' && substr($textcolor, 0, 4) !== 'rgb(') {
$textcolor = 'var(--wp--preset--color--' . $textcolor . ')';
}
?>
<div class="podcast-links" style="color: <?php echo $textcolor; ?>; text-align: <?php echo $align; ?>">
<?php
$spotify_url = get_field('spotify_url', get_the_ID());
$google_podcast_url = get_field('google_podcast_url', get_the_ID());
?>
<?php if ($spotify_url) { ?>
<div>
<a href="<?php echo $spotify_url; ?>" target="_blank" class="podcast-url-btn">Spotify</a>
</div>
<?php } ?>
<?php if ($google_podcast_url) { ?>
<div>
<a href="<?php echo $google_podcast_url; ?>" target="_blank" class="podcast-url-btn">Google Podcasts</a>
</div>
<?php } ?>
</div>
I can find the registered block and select it while editing a post or a page but not when I am editing a template or a template-part of my theme. What I try to achieve is add the block in my front-page inside a query-loop block. Do you have any idea why the registered block is available only in single post and page editor and not in the rest of my templates?
I am using Advanced Custom Fields PRO Version 5.9.5 and
WordPress 6.1.1 running Pentatonic theme.
I did face this problem but I fix it in block .json remove the line of the post types this will make your block appear everywhere.
“acf”: {
“mode”: “preview”,
“renderTemplate”: “all-fields-block.php”,
// remove this line “postTypes”: [ “post”,”page” ]`
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.