generate a static copy of the website footer html

Client website uses the service of a third-party content provider to maintain a TV programs page. This provider needs to have access to a file that gives the theme's footer html code.

I have managed to give him that, except that the javascript files, which should be in the footer, do not appear in the rendered html code.

Here is the complete code, sitting at /path/to/partnerfooter.php

define('WP_USE_THEMES', true);
require( '../wp-load.php' );

do_action('get_footer');
get_template_part('templates/footer');
wp_footer(); 
do_action('wp_enqueue_scripts'); // no go
?
  /body
/html

Topic footer third-party-applications customization Wordpress

Category Web


I managed to do it like this:

define('WP_USE_THEMES', true);
require( '../wp-load.php' );
// Register all scripts and styles
do_action('wp_enqueue_scripts');

// Execute footer hooks
do_action('get_footer');

// output the js
wp_print_footer_scripts();
wp_footer();

It also outputted the enqueued CSS files, so I tweaked it by making a helper function

function dequeue_scripts_or_styles($slug) {
    wp_dequeue_style( $slug );
    wp_deregister_style( $slug );
}

So the final code is

define('WP_USE_THEMES', true);
require( '../wp-load.php' );
// Register all scripts and styles
do_action('wp_enqueue_scripts');

// Remove things that should not sit in the footer
dequeue_scripts_or_styles( 'wc-responsive-video-scripts' );
dequeue_scripts_or_styles( 'sage/css' );


// Execute footer hooks
do_action('get_footer');

// output the js
wp_print_footer_scripts();
wp_footer();
?>
     </body>
 </html>

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.