A couple weeks ago, I'm working on a project that required me to develop a WordPress theme. One of the things that interested me was to create a block (html, in the front page) that change its background image randomly every time I reload the page. Here is how I did that: The main idea here is using Ajax to dynamically change background of a div tag to a random image loaded from a folder inside the theme's root every time I reload the home page. 1. functions.php add_action('init', 'enqueue_scripts_styles_init'); function enqueue_scripts_styles_init () { wp_enqueue_script( 'ajax-script', get_template_directory_uri().' /js/myscript.js ', array('jquery')); wp_localize_script( 'ajax-script', 'ajax_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); } add_action('wp_ajax_get_rand_img', 'get_rand_img'); add_action('wp_ajax_nopriv_get_rand_img', 'get_rand_...