Your problem is one of formatting:
<?php
add_action( 'wp_footer', 'wpse203799_footerscript', '30' ); }?>
There’s a very good reason that programmers follow coding standards, and use editors that automatically format and indent code. If we do these to the code used here, we’ll see this:
<?php
add_action( 'wp_footer', 'wpse203799_footerscript', '30' );
}
?>
This means that the function is never hooked into wp_footer
because the add_action
call is inside the function. The only way to hook it with the code written like this is to call the function itself, which is not what you want.
Instead, move the add_action
call outside of the function so that it’s always called