• I’m struggling to find anything regarding how to display custom fields in the new WordPress non-PHP templates. I’m not even seeing consistent language on what to call it, WordPress 6, FSE, block themes, etc. Multiple sources, including the link at the bottom of page/post editor in WP admin point here, but no mention as far as I can find regarding how to do this.
    I’m making my own WordPress FSE theme. How do I include a custom field value from a post in a page like single.html?

Viewing 5 replies - 1 through 5 (of 5 total)
  • In the new WordPress block-based editor (also known as the WordPress editor or the Gutenberg editor), you can display custom fields in your theme using the Custom Fields block. This block allows you to insert a custom field value into your post or page content by specifying the custom field name.

    To use the Custom Fields block, follow these steps:

    1. Create a new post or page, or edit an existing one.
    2. In the editor, click on the “+” icon to add a new block.
    3. Search for “Custom Fields” and select it.
    4. In the block settings, enter the name of the custom field you want to display.
    5. Save your post or page.

    The value of the custom field will be displayed in your post or page content wherever you insert the Custom Fields block.

    If you want to display the custom field value in a theme template file, such as single.html, you can use the get_post_meta function. This function retrieves the value of a custom field for a given post.

    Here’s an example of how you can use get_post_meta to display a custom field value in a theme template file:

    $custom_field_value = get_post_meta( get_the_ID(), 'custom_field_name', true );
    echo $custom_field_value;

    Replace ‘custom_field_name’ with the actual name of your custom field. The third parameter (true) specifies that the function should return the value as a single string rather than an array.

    I hope this helps! Let me know if you have any questions.

    Thread Starter zarwell

    (@zarwell)

    Thx for the very quick response. This might explain why I’m stuck, I don’t see Custom Fields when searching blocks in a post or page. Here’s a video of what I get: https://www.screencast.com/t/so5xfsKwOzx0
    Is my theme not being identified correctly or something?

    Hi @zarwell
    So you’re not using the ACF plugin to create custom fields? If not, you could follow this article and Let me know how that goes! ??

    Thread Starter zarwell

    (@zarwell)

    Thanks again, but nothing seems to work. I have tried both with and without the free ACF plugin, but regardless I don’t get Custom Fields or anything like it in the block search. In the video I provided I had ACF disabled, but I’ve activated it again to try. No luck. I have been able to use shortcode, [acf field=”location_latitude”], to insert the post field successfully into a post, but only in the admin editor. I can’t get anything to work adding it to a page.

    Thanks for the article you provided, but it like everything else I’ve found online only provides examples for doing this with PHP.

    Any idea why I don’t see Custom Fields anywhere in my Blocks? Anything else I can try?

    Moderator bcworkz

    (@bcworkz)

    A Custom Field block is related to ACF, there is no such block in the core editor. If you have trouble with the ACF plugin, I recommend asking for help in their dedicated support forum.

    As for displaying custom fields in a block theme without ACF, a shortcode should do the trick if it is inserted in content via the Shortcode block. If this doesn’t work as expected, there is likely an issue with your shortcode implementation. A more FSE-centric approach would be to develop your own custom block to display your custom fields.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to display custom fields in WP 6.1 FSE pages’ is closed to new replies.