Notes
This template page requires the jQuery library. Loading the library cannot be done within the template page code itself, it must be done outside and before the page is loaded. For that reason, the following code is added to the ‘functions.php’ file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | /* * Must do this before the ‘get_header’ function is called */ add_action( ‘wp_head’, ‘avp_sitemap_index_header’ ); function avp_sitemap_index_header() { if ( is_page_template( ‘sitemap-index.php’ ) ) { wp_register_style( ‘sitemap-index-css’, ( get_stylesheet_directory_uri() . ‘/sitemap-index.css’ ) ); wp_enqueue_style( ‘sitemap-index-css’ ); wp_register_script( ‘sitemap-index-jquery’, ( get_stylesheet_directory_uri() . ‘/sitemap-index.js’ ) ); wp_enqueue_script( ‘sitemap-index-jquery’, array( ‘jquery’ ) ); wp_enqueue_script( ‘jquery’ ); } } |
The function here is also used to register and enqueue the CSS style sheet and the jQuery script file file. Note the use of the ‘is_page_template()’ function with the sitemap template file name given as the function parameter to specify that only the given template page will load the desired styles and scripts.
The short URL of the present article is: http://www.terryobrien.me/1i3n4
Personal Links