• Resolved donpi73

    (@donpi73)


    As the W3C Validation Service outputs many alert info messages about “Trailing slash on void elements has no effect and interacts badly with unquoted attribute values.”…

    Can you rewrite your HTML minify function to remove trailing slashes to void elements, as Autoptimize plugin has?

    Autoptimize can be configured to output void elements without trailing slashes, by using a filter with the autoptimize_html_after_minify hook — like this:

    add_filter( 'autoptimize_html_after_minify', function( $html ) {
        return str_replace( '/>', '>', $html );
    } );

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

Viewing 15 replies - 1 through 15 (of 17 total)
  • Plugin Support qtwrk

    (@qtwrk)

    Hi,

    thanks for the info

    I have forwarded this to our devs

    Best regards,

    Thread Starter donpi73

    (@donpi73)

    Any News?

    Plugin Support Hai Zheng⚡

    (@hailite)

    We have a filter litespeed_buffer_finalize. You can use it to alter the content after minified.

    Thread Starter donpi73

    (@donpi73)

    Ok.

    Can you tell me how can I use it to remove trailing slashes?

    Is there any official documentation on how to use it?

    Thanks

    Plugin Support qtwrk

    (@qtwrk)

    please check this page

    Thread Starter donpi73

    (@donpi73)

    Thanks!

    It works like a charm!

    Thread Starter donpi73

    (@donpi73)

    Unfortunately I already have to repress my sense of satisfaction, because it’s evident that the modification also acts on the administration dashboard

    In fact, after having inserted the code

    function remove_trailing_slashes( $content ) {
    return str_replace( '/>', '>', $content );
    }
    add_filter( 'litespeed_buffer_after', 'remove_trailing_slashes', 0);

    the featured image no longer appears inside the post editor

    Plugin Support qtwrk

    (@qtwrk)

    you may need to put some condition check , like

    function remove_trailing_slashes( $content ) {
    if ( is_admin()){
    return $content;
    }
    else {
    return str_replace( '/>', '>', $content );
    }
    }
    add_filter( 'litespeed_buffer_after', 'remove_trailing_slashes', 0);

    to make sure it only replaces on front page

    Thread Starter donpi73

    (@donpi73)

    I’ve already tried, and – unfortunately – it doesn’t work.

    Also, I wonder why litespeed also acts on the admin dashboard… shouldn’t it only act on the frontend?


    Isn’t there a filter that can act only and exclusively on the html part of the website frontend?

    Plugin Support qtwrk

    (@qtwrk)

    by default, it should exclude any wp-admin page , please check the debug log , see what logs says

    Thread Starter donpi73

    (@donpi73)

    I’ve saved two logs: one without the “remove traling” function and one with the function.

    They differ in many lines (comparing with “compare” plugin in Notepad++), but I can’t find the problem…

    Some commands are reversed in order, others are missing, but I can’t find explicit error messages.

    I think that the change, although the administration dashboard area is excluded from the cache, interferes with some internal command.

    Plugin Support qtwrk

    (@qtwrk)

    please share me both logs

    Thread Starter donpi73

    (@donpi73)

    Ok.

    I’ve uploaded the logs in my Google Drive.

    You can download them here:

    https://drive.google.com/drive/folders/1RKKUD_PugzhS-BjHmLR0rguuhvFYyjlQ?usp=share_link

    Plugin Support qtwrk

    (@qtwrk)

    let’s try this other way around

    change the part if ( is_admin()){ to

    if (strops($_SERVER['REQUEST_URI'], 'wp-') !== FALSE) {

    see if it helps

    Thread Starter donpi73

    (@donpi73)

    Sorry. Nothing to do.

    Same behaviour.

    But… Excuse me if I ask: isn’t it easier for you to insert a command (that can be activated or not on Page Optimization/HTML Settings) in the function that takes care of minifying the HTML file (and ONLY THAT) to remove trailing slashes?

    That’s just two lines of code to add!

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘HTML minify: output void elements without trailing slashes’ is closed to new replies.