Add Site wide background image to export
bph opened this issue · comments
With Gutenberg 18.1 comes side wide background image feature.
The set image should be part of the theme export
Actually, I am not sure if that's actually necessary. It turns out when the theme is uploaded to a site that has the Gutenberg plugin enabled (18.1) then the site-wide background image shows out of the box. I just can't see the image file in any folder of the downloaded theme.
~~It's the most curious thing. ~~
Of course, it showed up because the LocalWP site where I uploaded the background image was still active. 🤦♀️
It's hard-coded in the theme.json
"background": {
"backgroundImage": {
"id": 195,
"source": "file",
"title": "3032452",
"url": "http://localhost:10115/wp-content/uploads/2024/04/3032452-scaled.jpg"
},
"backgroundPosition": "28.000000000000004% 59%",
"backgroundSize": "auto"
We have added the theme-ization of SOME blocks such as image and cover block. We haven't added anything to theme.json yet though and this seems like it would be the best first candidate. It would be very similar and not terribly difficult.
Hmm, I am not sure what your comments is getting at. And it seems I didn't make myself clear enought.
A side wide background image is not at a block level like an image or a cover block.
![Screenshot 2024-04-18 at 16 21 27](https://private-user-images.githubusercontent.com/39980/323904092-dc71b3da-d73e-4b85-b32f-11de2abc961e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM5Njg5MzcsIm5iZiI6MTcyMzk2ODYzNywicGF0aCI6Ii8zOTk4MC8zMjM5MDQwOTItZGM3MWIzZGEtZDczZS00Yjg1LWIzMmYtMTFkZTJhYmM5NjFlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE4VDA4MTAzN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWYzYmZkMTM1MjliYTBmODE0ZmVjMmQ2OTY0MDViNmI4OWZjMmE2ODVkNDg1Y2JhOGEwYzM1YmU3ZTU5YWEzN2ImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.i-UIqkT7UldStu0sJK-rU_IZq5ZIooC3CYqAHFapOv4)
What did I expect?
That the background image was:
- downloaded into the /assets folder like fonts are downloaded in the /fonts folder and
- the location in the theme.json is adopted to the relative location in the asset folder.
{
"background": {
"backgroundImage": {
"id": 195,
"source": "file",
"title": "3032452",
"url": "../assets/2024/04/3032452-scaled.jpg"
},
"backgroundPosition": "28.000000000000004% 59%",
"backgroundSize": "auto"
}
How to test it:
- Needs Gutenberg 18.1.x
- Create a blank theme
- Add a background image to the site via Site Editor > Styles > Style Icon > see screenshot below for location.
- Save
- Save it in CBT
- Download in zip
- delete the background image from the media library
- upload the zip file to a different site.
- You will notice that the background image is not showing on the new site. The reason is that hardcoded link to the existing site in the theme.json file.
![Screenshot 2024-04-19 at 11 30 34](https://private-user-images.githubusercontent.com/39980/323908739-c8bf06ed-9795-4b8b-834c-a0881236f4ea.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM5Njg5MzcsIm5iZiI6MTcyMzk2ODYzNywicGF0aCI6Ii8zOTk4MC8zMjM5MDg3MzktYzhiZjA2ZWQtOTc5NS00YjhiLTgzNGMtYTA4ODEyMzZmNGVhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE4VDA4MTAzN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQwZjc5NmQyZDdkZThhMzZhOTFkMTg4ZmNjMWMwMzdmMzk3MDg0Yjg4YzNkODE3MjMwNDhhOWE5NGIyNzY5NjcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.6iK3Ke9nSs2lSb_EMwo1q1l7xZXIRDCymkZc-aoJV2U)
Hmm, I am not sure what your comments is getting at. And it seems I didn't make myself clear enought.
A side wide background image is not at a block level like an image or a cover block.
I was just noting that the type of processing we do for blocks (download a linked asset to a local folder, changing the source to point to the now theme-local asset) is the same processing we would do for the sitewide background image in theme.json. We haven't done any type of processing like that on theme.json but it's very similar to what we are already doing for blocks and shouldn't be very difficult.
Related PR in Gutenberg: WordPress/gutenberg#60578