Created
September 21, 2020 02:57
-
-
Save giorgioriccardi/7fa7a290a1f0d09865d272193f20295e to your computer and use it in GitHub Desktop.
WordPess add a script only for a specific page
This file contains hidden or 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 | |
/********************************************************/ | |
// Add GameMaker scripts in WordPress <head> | |
/********************************************************/ | |
add_action('wp_head', 'ssws_Add_GameMaker_scripts'); | |
function ssws_Add_GameMaker_scripts() { | |
// wrap the videogame code in an if() condition to match only a certain condition(s): | |
// if (is_page( 42 )) { // match page ID, less flexible | |
if (is_page( 'games' )) { // match page slug | |
// https://developer.wordpress.org/reference/functions/is_page/#user-contributed-notes | |
?> | |
<script type="text/javascript" src="html5game/Dinosaur Detective.js?AEMAC=1661759149"></script> | |
<script> | |
window.onload = GameMaker_Init; | |
</script> | |
<?php | |
} // end if | |
} | |
// https://codex.wordpress.org/Conditional_Tags |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment