I’m building a WordPress based AJAX site, where I use jQuery and the .get() method to display content from single post pages onto the same page. Now I don’t want to include the header/footer when retrieving this data but I still need to make it SEO friendly and have all the single pages accessible elsewhere. Is it possible to write a condition in the single.php file that would accomplish this?
Tried using
<?php if (!is_home()) { get_header(); } ?>
When accessing the page in particular it works; the header is included. But if I load the url through .get() on the home page I get all content and end up with a double header. Somehow WP thinks it’s at the home location even though it’s running the condition remotely.
Call your AJAX functions at
init hook:And use
exitjust after output your data (usingecho):