• I am trying to use browser in-built PDF viewing capabilities via an HTML <object/> block, using the text (non-visual) editor as follows:

    <!-- wp:html -->
    <object data="https://cadieuxbicycleclub.com/wp-content/uploads/2022/07/2022_Hines_TT.pdf?#zoom=85&scrollbar=0&toolbar=1&navpanes=1" type="application/pdf" width="100%">
        <embed src="https://cadieuxbicycleclub.com/wp-content/uploads/2022/07/2022_Hines_TT.pdf" type="application/pdf"/>
            <p>This browser does not support PDFs. Please download the PDF to view it: <a href="https://cadieuxbicycleclub.com/wp-content/uploads/2022/07/2022_Hines_TT.pdf">Download PDF</a>.</p>
    </object>
    <!-- /wp:html -->1st

    The problem is at render time, those &’s are converted to &’s.
    Here is what I see in the HTLML source upon viewing the page:

    
    
    <object data="https://cadieuxbicycleclub.com/wp-content/uploads/2022/07/2022_Hines_TT.pdf?#zoom=85&scrollbar=0&toolbar=1&navpanes=1" type="application/pdf" width="100%">
        <embed src="https://cadieuxbicycleclub.com/wp-content/uploads/2022/07/2022_Hines_TT.pdf" type="application/pdf">
            <p>This browser does not support PDFs. Please download the PDF to view it: <a href="https://cadieuxbicycleclub.com/wp-content/uploads/2022/07/2022_Hines_TT.pdf">Download PDF</a>.</p>
    </object>
    

    So, as you can see, my exact HTML was not preserved, despite being in a wp:html block.

    I checked the DB contents for the page and it did get stored correctly, which confirms the conversion to & is happening at render time.

    NOTE: I was also having age-old problems with Gutenberg doing the conversion and storing it incorrectly, so to fix that I installed the Classic Editor plugin so I could get the page stored correctly. But even so I am still facing the issue at render time.

    • This topic was modified 3 years, 8 months ago by t-p. Reason: Moved to Fixing WordPress from Everything else WordPress
    • This topic was modified 3 years, 8 months ago by Steven Stern (sterndata).

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    HTML entities are nearly impossible to talk about accurately in these forums because of auto-conversions. I believe what you’re trying to say is the &s in the data attribute URL are improperly converted to the HTML entity & #038; (except without the space shown here).

    HTML entities are valid for HTML, but not in URLs, so being in an HTML block would not protect characters in an URL. It’s necessary to escape HTML output for security reasons. The way to get around this is to create a custom shortcode. Shortcode output is not processed like normal HTML content. Your shortcode is expected to implement proper escaping for itself.

    Your custom shortcode could take an URL attribute and construct a proper embed object from it. Something like [pdf url="2022/07/2022_Hines_TT.pdf"].
    https://developer.wordpress.org/plugins/shortcodes/

Viewing 1 replies (of 1 total)

The topic ‘Age old & to & conversion issue’ is closed to new replies.