• I’m feeling pretty dumb right now.

    I just want to build an author template, like I’ve been doing for over a decade now, but I want to do it in a block theme. In the past I’d get the author meta using the author ID, but I can’t get that in the template file. I can’t even string together the proper words to find a solution in a search engine.

    Is there something like this (https://codex.www.ads-software.com/Author_Templates) but for block themes?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator t-p

    (@t-p)

    Thread Starter justin.garner23

    (@justingarner23)

    Thanks for the quick response @t-p!

    How does one go about adding author meta, though? I didn’t see anything about accessing any of the other meta users add to their profile that we’ve traditionally been able to add to author templates, like outlined here: https://codex.www.ads-software.com/Author_Templates#Using_Author_Information

    Moderator bcworkz

    (@bcworkz)

    How does one go about adding author meta?

    Do you mean adding custom meta data via the user’s profile screen?

    While block editor content uses a very different paradigm than the classic editor did, the user profile screen remains much as it has been for years. The profile screen’s PHP code has a number of action hooks you can use to output additional form fields. Then use one of the action or filter hooks that fire when user data is inserted or updated to validate, sanitize, and save your added meta data.

    For example, use the ‘personal_options’ action to output additional form fields. Then use the ‘insert_user_meta’ filter to add your custom values to what WP will save as user meta data.

    Thread Starter justin.garner23

    (@justingarner23)

    @bcworkz, I’m referring to displaying custom meta on the front end, on the author page template.

    For example: My classic theme added fields to the user profile page via ACF. Those fields get stored in the wp_usermeta table as example_field. In author.php I could use get_user_meta( 'example_field', $author_id ); to access the value and use it in the template.

    Now, I know that this isn’t the place for ACF support and I’m not seeking help with getting ACF field data exclusively. If I were to add custom values as you suggested, using insert_user_meta, I’d want to be able to access those values directly, too.

    As a temporary solution, I’ve decided that a hybrid approach is going to be necessary (for my case) until I’m able to learn more about the block based approach. Going this route I’m able to access all the data I’m needing and still take a block-forward approach to development.

    Moderator bcworkz

    (@bcworkz)

    If you have a classic theme, you could modify the template that’s used for author archives. Echo out the return from get_user_meta() (or whatever similar function) where ever you like, as long as it’s not within post content.

    If your theme is subject to periodic updates, keep you modified template in a child theme.

    For output within post content, you can use a shortcode or a custom block.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Block Theme Author Template’ is closed to new replies.