1

How do I pass author details such as name, bio and avatar to a block?

  • 1
    Is this for saving or display? I'd keep in mind that you could get what you asked for but have the problem that changing the author doesn't update the block if you're not careful – Tom J Nowell Jul 3 at 21:18
  • For display I would rather the block only get this information rather than have a user pick it that way it's controlled from wp itself. So if i create the block it gets the name and bio of the post author of the post but if I change it from the post edit screen it updates to the new author if that makes sense. – neverin772 Jul 4 at 8:41
0

Use a server side rendered block, use register_block_type to register the block in PHP, and specify a PHP function to render the blocks output using the render_callback option.

Then, in the blocks JS implementation, return null in the save method. You can retrieve the current author from the WP Core data store for previewing purposes when inside the block editor, but it isn't necessary for it to work on the frontend

  • Ok so how do I call the current author using core/data ? – neverin772 Jul 4 at 14:34
  • Eh I'm not sure how to do that off the top of my head, but it shouldn't be needed to get it functional on the frontend – Tom J Nowell Jul 4 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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