Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building dynamic attachment templates in block themes #199

Closed
justintadlock opened this issue Jan 4, 2024 Discussed in #192 · 8 comments
Closed

Building dynamic attachment templates in block themes #199

justintadlock opened this issue Jan 4, 2024 Discussed in #192 · 8 comments
Assignees

Comments

@justintadlock
Copy link

Discussed in #192

Originally posted by justintadlock December 19, 2023
Block themes support attachment.html templates, but WordPress is not very "smart" about handling the output of media for attachment views. At the moment, there are no dynamic Image, Audio, and Video blocks that automatically pick up the current attachment media file on the front end.

Yes, attachments views are now disabled by default for new WP installs (as of 6.4?), but there are still many use cases where attachment templates are needed.

Typically, I don't like to propose topics for the Dev Blog that are outside the standards of theme dev, but this is one of those situations that requires a bit of hacking to make things work as well as they did in classic. That's unfortunate, but this is a missing piece of block theme dev with no instructions/docs (AFAIK) on the best way to handle this.

I'm proposing a tutorial on how to filter the Post Content block for attachment views to insert a sort of dynamic template partial/pattern that allows theme authors to control the output of attachment pages.

I have a working example in my own theme that I could break down for this tutorial:

@justintadlock
Copy link
Author

Example repository: https://github.com/justintadlock/dynamic-attachments

I'll probably begin writing the tutorial on this one next week.

@justintadlock
Copy link
Author

@justintadlock
Copy link
Author

@bph
Copy link
Collaborator

bph commented Jan 18, 2024

1st review done. @justintadlock I left a few minor comments, mostly tone and filler. I appreciate this post very much, as it demonstrates clearly, that PHP can be used to while creating block themes and prior solutions can be integrated.

@justintadlock
Copy link
Author

Thank you for the review, @bph. As always, great feedback.

I had a couple of in-comment questions, but I'm moving this to needs 2nd review since the other edits have been resolved.

@thetinyl
Copy link

@justintadlock I've just finished a 2nd review of your piece. Some minor copy edits and small nitpicks to consider. Looks good otherwise. 👍

@justintadlock
Copy link
Author

Social copy:

From the WordPress Developer Blog: learn how to dynamically customize media output in block themes:

https://developer.wordpress.org/news/2024/01/22/building-dynamic-block-based-attachment-templates-in-themes/

@ndiego
Copy link
Member

ndiego commented Jan 29, 2024

Social post scheduled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Published (Done)
Development

No branches or pull requests

4 participants