Last active
January 24, 2020 01:34
-
-
Save westonruter/2b1b64249befa3b39adccc9f139f9aba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Add Inline Scripts (and Styles) | |
* Description: Test case to debug AMP plugin source attribution problems. | |
* Author: Weston Ruter | |
* Author URI: https://weston.ruter.net/ | |
* Plugin URI: https://amp-wp.org | |
* License: GPLv2 or later | |
*/ | |
namespace Add_Inline_Scripts; | |
/** | |
* Add inline style. | |
*/ | |
function enqueue_assets() { | |
wp_enqueue_script( 'underscore' ); | |
wp_localize_script( 'underscore', 'Hello_Underscores', [ 'message' => 'Hello wp_localize_script()!' ] ); | |
wp_add_inline_script( 'underscore', '/*Hello wp_add_inline_script( before )!*/', 'before' ); | |
wp_add_inline_script( 'underscore', '/*Hello wp_add_inline_script( after )!*/', 'after' ); | |
wp_add_inline_style( get_template() . '-style', '#add-inline-scripts-styled { color: blue; }' ); | |
} | |
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_assets', 11 ); | |
add_action( | |
'wp_footer', | |
function () { | |
echo '<div id="add-inline-scripts-styled">Styled by add-inline-scripts</div>'; | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Add More Inline Scripts | |
* Description: Test case to debug AMP plugin source attribution problems. | |
* Author: Weston Ruter | |
* Author URI: https://weston.ruter.net/ | |
* Plugin URI: https://amp-wp.org | |
* License: GPLv2 or later | |
*/ | |
namespace Add_More_Inline_Scripts; | |
/** | |
* Add inline style. | |
*/ | |
function enqueue_assets() { | |
wp_enqueue_script( 'underscore' ); | |
wp_localize_script( 'underscore', 'Hola_Underscores', [ 'message' => 'Hola wp_localize_script()!' ] ); | |
wp_add_inline_script( 'underscore', '/*Hola wp_add_inline_script( before )!*/', 'before' ); | |
wp_add_inline_script( 'underscore', '/*Hola wp_add_inline_script( after )!*/', 'after' ); | |
wp_add_inline_style( get_template() . '-style', '#add-more-inline-scripts-styled { color: red; }' ); | |
} | |
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_assets', 20 ); | |
add_action( | |
'wp_footer', | |
function () { | |
echo '<div id="add-more-inline-scripts-styled">Styled by add-more-inline-scripts</div>'; | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment