Do not embed PDF automatically in file block
Originally reported on a Fixing WordPress forum topic and Trac #54062
By default, the new embeddable PDF option (PR #30857) is toggled on, so people who do not want to embed their PDFs need to uncheck the toggle every time.

Fixing this may be as simple as switching the displayPreview from true to false:
https://github.com/WordPress/gutenberg/blob/8714f668dde8120068028f0975adac5fdaa8f30e/packages/block-library/src/file/edit.js#L125
I'm hopeful this could be backported to the 5.8 branch.
For further consideration, though, could the toggle start with the user's choice from a previous PDF file block after the first?
I think having it remember the choice works, but I guess I would like to know really how many users want this option first. If it's more likely to be something people want embedded, then I'd say leave it on works - it also means it's discovered. If it is off it would need the discovery of the feature also.
The discussion on #19077 gives a few reasons why people might choose not to embed a PDF file, including accessibility concerns and poor mobile support. Even users who like embedding a PDF probably would not want multiple embeds on the same page.
For discoverability, the inline embed option is already at the top of the Block settings sidebar panel. That makes it more findable than the Text link settings and the Download link option.
(also, it's the File block)
This is a major annoyance for myself and my collegues as we're often required to add many PDF documents at once. Further more we are constantly being asked by clients to make off by default as they too are getting frustrated.
I've been looking around to find possible solutions and every post I read explains the frustration this is causing. As mentioned by Sabernhardt, it's not like it's hard to see / find for those that do want to use it.
I see this as an issue that should not rely on a per-user last-used preference. The problem I see is that I need to know that every user's experience is the same once I've created a template or page for them to update.
In my use case, I have a 5x5 table with approximately 20 PDF files linked. At the moment, every time a user updates a PDF in the table it changes that formatted link to an embed, which then requires the user to select the embed and then disable it again. They may need to edit other pages that do have an embed, so can't rely on last chosen setting. Ideally a file link would hold its link after replacement of a file rather than converting to an embed without warning
Looking at this I do think that it would be nice to have a way for theme authors to define wether they want to support the rich preview of files or not. There are many different usecases where it makes perfect sense to show the inline preview. But there also are many instances where from a design perspective it doesn't make sense. And being able to define that support in the settings of a theme.json file for example would be really cool.
I'm torn wether it should be just a boolean to enable / dissable support globally or wether it should give you more granular controll to choose wether the default for certain types should be true / false but still letting the end user make the final call.
{
"settings": {
"blocks": {
"core/file": {
"enablePreview: false
}
}
}
}
or
{
"settings": {
"blocks": {
"core/file": {
"enablePreview": {
"default": false,
"pdf": true
}
}
}
}
}
just as two examples for what a possible syntax could look like.
Looking at this I do think that it would be nice to have a way for theme authors to define wether they want to support the rich preview of files or not. There are many different usecases where it makes perfect sense to show the inline preview. But there also are many instances where from a design perspective it doesn't make sense. And being able to define that support in the settings of a
theme.jsonfile for example would be really cool.I'm torn wether it should be just a
booleanto enable / dissable support globally or wether it should give you more granular controll to choose wether the default for certain types should betrue/falsebut still letting the end user make the final call.{ "settings": { "blocks": { "core/file": { "enablePreview: false } } } }or
{ "settings": { "blocks": { "core/file": { "enablePreview": { "default": false, "pdf": true } } } } }just as two examples for what a possible syntax could look like.
It didn't working for me
@Pauxster Sorry for the confusion here. My comment was a suggestion for the development team on how an API for this could look. But that has not been implemented and is not an actual option right now. Only a suggestion from my side.
+1 … there should be an option to completely disable this file preview.
Auto-embedding PDFs is a huge step backwards in terms of accessibility, speed and cross platform compatibility. There were already a number of quality third party plugins that provided this functionality for those that needed it, so not sure it brings any benefit to counterbalance it's disadvantages.
The default to embed PDF is a major annoyance for our users. We definitely like to be able to default to having a link to the file.
Does anyone know if it's possible to change the default right now? I tried doing so with a registerBlockVariation like this:
/* DOES NOT WORK IN PRACTICE! */
wp.blocks.registerBlockVariation(
'core/file',
{
isDefault: true,
attributes: {
displayPreview: false
},
}
);
This inserts a block with displayPreview set to false, but then that setting is changed when inserting a PDF.
I don't know, if some one other have a better workaround, but in the meanwhile here is mine.
Create a cronjob with this command, which changes the necessary file (browser cache must be deleted after modification):
sed -i 's/url.endsWith(".pdf");/url.endsWith(".pdff");/' /path/to/wordpress/installation/wp-includes/js/dist/block-library.min.js
This is my cronjob entry, so that it searches 3 times a day for the string, in case an automatic update was done.
5 6,12,18 * * * su www-data -c "sed -i 's/url.endsWith(".pdf");/url.endsWith(".pdff");/' /path/to/wordpress/installation/wp-includes/js/dist/block-library.min.js"
I hope for a better solution by Wordpress.
Edit: Actually I'm using Wordpress 5.9.1
It's for issues like this that people (in this case rightfully) blast Gutenberg. This is a major usability issue.
I also wish to disable to embed by default.
Strongly in favor
Using JSON may be better, but I made a PR for the simpler method.
Plus one for this change. This is a major interruption to workflow. Has anyone figured out a temporary solution to change this default behaviour for now?
I'm also in favour of an option to switch this on or off by default. It is really confusing for content creators and at the moment everyone I know switches off the Show Inline Emded.
Was this feature implemented for accessibility reasons? Is it better for accessibility than a link to a pdf?
This is definitely not for accessibility; the PDF previews are more likely to be harmful to accessibility.
Now that user settings can be stored in user meta (https://github.com/WordPress/gutenberg/pull/39795), getting the user choice to be remembered can be much more broadly applied, and this preference should definitely be registered there.
I'd still prefer the default state for new users to have the embed off; embedding a file preview is, in my opinion, the exceptional use, not the normative use.