just put all your code like below with Everywhere location set.
<?php add_action('plugins_loaded', function(){ // put all the example code here }, 99);