I’am using simple ajax method to load content in wordpress site: i catch clicks on navigation links and add GET parameter to 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 check this parameter in templates of wordpress and if this parameter exists i do not include header and footer and load naked 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 page contain contactform7 shortcode, ajax submiting form doesn’t work because footer.php not includes js staff for form.
I tried to put wp_footer() function into page.php, but function not adding js scripts for form! If i put wp_head() in page.php too – wp_footer() works fine.
Any ideas please.
If you look on line 200 of wp-includes/default-filters.php, you’ll notice that scripts are enqueued with
wp_head
.This is why your scripts aren’t working.
wp_head()
is a critical function for Contact Form 7 to function properly. You need to still includewp_head()
, but don’t need to includewp_header()
in order for that to happen. For example, the following should keep things “naked”, but still allow scripts to be loaded:Make sure that
wp_head()
is still run within your document<head></head>
section.