Skip to content

Instantly share code, notes, and snippets.

@giorgioriccardi
Created September 21, 2020 02:57
Show Gist options
  • Save giorgioriccardi/7fa7a290a1f0d09865d272193f20295e to your computer and use it in GitHub Desktop.
Save giorgioriccardi/7fa7a290a1f0d09865d272193f20295e to your computer and use it in GitHub Desktop.
WordPess add a script only for a specific page
<?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