0

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>
  • Can you not just provide them static HTML? i.e. copy and send your rendered source code? The trouble with your current technique is it's not a true WordPress request, so a lot of actions/hooks/events that are probably responsible for enqueuing your various scripts aren't fired. – TheDeadMedic Jan 10 '17 at 17:15
  • 1
    You could at least try firing wp_enqueue_scripts before the get_template_part call. – TheDeadMedic Jan 10 '17 at 17:15
  • @TheDeadMedic yup, i figured it out. – pixeline Jan 10 '17 at 21:10
0

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>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.