How do I exclude .pdf files in HTML markup?

SLS needed

I have a conundrum I cannot seem to figure out!

I want to minify the HTML output of my site and have been doing it via some script in the functions file. It all works fine except in one irritating instance!

My site also serves PDF files (some static, some dynamically generated. The minification also tries to minify the PDFs and so they either don’t come out at all or are very broken.

I’m wondering if there is a way to exclude URLs that end in .pdf from a function?

  • Panos
    • SLS

    Hi Daniel ,

    I tried both snippets in my test site with some pdf links but they were working fine.

    I don’t think the script from would affect this, as of what I see removes white spaces, new lines and comments (I could be wrong though).

    So focusing on the script from could you try adding :

    if( strpos( $content, '.pdf' ) !== false ){
    $html .= $content;

    right after this:

    foreach ( $matches as $token ) {

    $tag = (isset($token['tag'])) ? strtolower($token['tag']) : null;
    $content = $token[0];

    and before this:

    if ( is_null( $tag ) ) {

    In gist file it should be line 44

    Please let us know if this helps :slight_smile:


  • Daniel
    • New Recruit

    Thank you very much for your response :relaxed:

    Sadly that didn’t help. Though it didn’t break anything either, the pdfs are still failing.

    I have a feeling it is down to the way the plugin that is masking their URL works.

    The link to one of the pdfs for example is something like this:

    Reason being that the PDF files are all stored in the plugin folder, so to mask the full path, that query string is used.

    ?qe_public_download is present in ALL pdf links, so maybe that is the key as to what needs excluding?



  • Panos
    • SLS

    Hi Daniel ,

    Sorry to hear it didn’t work :disappointed:

    If I understood correctly you are using a plugin for url masking? If this is the case could you deactivate it and check if the issue is fixed? Also could you check what is the difference in the pdf urls when that plugin is active and when not?


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.