Wp_footer () doesn't work without wp_head ()?

I'm using a simple ajax method to upload content to a wordpress site: I catch clicks on navigation links and add a GET parameter to the url:

jQuery('#topnav a').click(function(e){
e.preventDefault();
url = jQuery(this).attr('href');
jQuery.ajax({
     type: 'GET', 
     url: url,
     data: 'naked=1', // my parameter
     dataType: 'html',
     success: function(data){
                jQuery('#content').html(data); // load new content
            });     
        }       
    });
});

      

after i checked this parameter in wordpress templates and if this parameter exists i don't include header and footer and load the bare content:

<?php
/**
* page.php
* @package WordPress
* @subpackage clean
*/
if (!isset($_GET['naked'])) get_header(); // if parameter exist do not load header ?> 
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); // cycle wp start ?>
    <h1><?php the_title(); ?></h1>
    <?php the_content(); ?>
<?php endwhile; // cycle wp end
if (!isset($_GET['naked'])) get_footer(); // if parameter exist do not load footer ?>

      

This method worked fine, but if the page contains shortcode contactform7 the ajax submission form doesn't work because footer.php doesn't include js staff for the form.

I tried to put the wp_footer () function in page.php, but the function doesn't add any js scripts for the form! ... If I put wp_head () in page.php too - wp_footer () works fine.

Any ideas please.

+3


source to share


1 answer


If you look at line 200 from wp-includes / default-filters.php , you will notice the scripts are queued wp_head

.

This is why your scripts are not working. wp_head()

is a critical feature for Contact Form 7 to work properly. You need to enable it wp_head()

, but you don't need to wp_header()

enable it for this to happen. For example, the following should contain things "naked" but still allow scripts to be loaded:



if ( !isset($_GET['naked']) ) {
    get_header(); // if parameter exist do not load header
} else {
    wp_head(); // still include wp_head(), but without the rest of the "header"
}

      

Make sure wp_head()

to still execute in the document <head></head>

.

+2


source







All Articles