0

WordPress's Twenty Twenty-Four theme makes it possible to add custom fields directly in the editor, but I simply cannot figure out how to display such fields within a post or page (without a plugin).

The the_meta() only displays the traditional meta data (ie author & date).

I created a 'single.php' file along with get_post_meta(), the custom fields show up, but none of the formatting (header, footer etc) disappeared.

If I edit the template, then only the meta block is available, but no way of accessing the custom fields.

Any tips would be appreciated!

3
  • 2
    do you mean the custom fields metabox when editing a post? When you mention adding custom fields there are several things this could be referring to, including setting/adding/using, and upcoming features. 2024 itself does none of these things so this is a general WordPress thing not specific to that theme, though it is important that it is a block theme that doesn't use PHP files to display its templates
    – Tom J Nowell
    Commented Jan 17 at 19:12
  • Custom fields are a built-in feature in WordPress's Twenty Twenty-Four theme--you can see it on the post editing page, but you have to turned it on. Given it's built-in, I assumed it'd be just as easily be displayed, but I haven't figured out how to display the custom fields -- hence my question.
    – YCode
    Commented Jan 22 at 17:55
  • 1
    they're not specific or unique to that theme, the custom fields metabox you're seeing is coming from WordPress core and is decades old and predates both 2024 and block themes
    – Tom J Nowell
    Commented Jan 22 at 20:06

2 Answers 2

1

WordPress's Twenty Twenty-Four theme makes it possible to add custom fields directly in the editor

This UI is not coming from TwentyTwentyFour, and was added to WP decades ago:

https://wordpress.org/documentation/article/assign-custom-fields/

It predates 2024/2023 and was even present when the original Kubrick theme was the default theme, this is because it's a part of WordPress itself.

Instead we can generalise your question to:

Q: How Do I Display The Values of custom Fields in a Block Theme?

Since you can't put a snippet of PHP in a template like a classic theme that says echo get_post_meta(....etc you're forced to write code using one of these options:

  • via a shortcode
  • in a server rendered/dynamic block (best)
  • via a plugin

At the time of writing they're discussig the replacement of this particular UI and how using custom fields in block themes might work in the future.

The best detailing of this is the 12 minute section of the 2023 State of the word video where the technical lead demos it:

https://www.youtube.com/watch?v=c7M4mBVgP3Y

See 23 minutes in.

Also:

I created a 'single.php' file along with get_post_meta(), the custom fields show up, but none of the formatting (header, footer etc) disappeared.

This is because 2024 is a block theme, not a classic PHP theme. Using single.php completely bypasses the block based templating system.

This is the old way of doing things.

If I edit the template, then only the meta block is available, but no way of accessing the custom fields.

As I mentioned earlier, this is because this functionality hasn't been implemented in the UI and requires a developer to write code for a block. Shortcodes via the shortcode block may also be an option.

1
  • Thanks for the explanation. The State of the Word video is where I originally got the idea of using "built-in" custom fields. I found the docs to be vague and confusing: If they encourage users to use a plugin, ACF would do the job, so I wondered what the excitement (in the video) for this new thing was all about. So presumably custom fields will be better implemented at some point.
    – YCode
    Commented Jan 24 at 3:40
1

The easiest way I've found of doing this is to install the plugin ACF Views Lite, which you can do from Plugins > add new plugin, and create a view for your field. This will generate a short-code that you can place anywhere you like.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.