Make WordPress Core


Ignore:
Timestamp:
01/03/2015 05:07:15 AM (10 years ago)
Author:
wonderboymusic
Message:

Add the ability to print data *after* a script, whether it is concatenated or not:

  • Add a third argument to WP_Scripts->print_extra_script(), $key, which will be passed to ->get_data() (no longer passes hardcoded 'data')
  • When $key is set to 'data-after', the inline script will be printed after the <script> tag. If the scripts are being concatenated, all scripts' 'data-after' data will be printed after the concatenated <script> has been rendered.

Props hakre, wonderboymusic.
Fixes #25277.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/script-loader.php

    r31016 r31032  
    858858    }
    859859
    860     if ( !empty($wp_scripts->print_html) )
     860    if ( ! empty( $wp_scripts->print_html ) ) {
    861861        echo $wp_scripts->print_html;
     862    }
     863
     864    if ( ! empty( $wp_scripts->print_after_html ) ) {
     865        if ( $wp_scripts->do_concat ) {
     866            echo "<script type='text/javascript'>\n";
     867            echo "/* <![CDATA[ */\n"; // not needed in HTML 5
     868            echo trim( $wp_scripts->print_after_html ) . "\n";
     869            echo "/* ]]> */\n";
     870            echo "</script>\n";
     871        } else {
     872            echo $wp_scripts->print_after_html;
     873        }
     874    }
    862875}
    863876
Note: See TracChangeset for help on using the changeset viewer.