Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How can I get WordPress to render a page without it adding any addtional html? I'm trying to build a dialog that will work on mobile devices and I only want to show that dialog and not have any of the standard wordpress content around it.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You have to implement your own hook for template_redirect action:

add_action( 'template_redirect', 'wpse8170_template_redirect', 1 );
function wpse8170_template_redirect() {
    global $wp_query;

    // check if it is not a page or if it is front page, then exit from the hook
    if ( !$wp_query->is_page() || $wp_query->is_front_page() ) {
        return;
    }

    // check queried object, if it is not a specific page, then exit from the hook
    $page = get_queried_object();
    if ( $page->ID != 777 ) { // your page ID 
        return;
    }

    // render header
    get_header();

    // ... render your content here ....

    // render footer
    get_footer();

    exit;
}
share|improve this answer
    
Beautiful. This is an excellent solution. Thanks so much. –  spinlock Feb 15 '13 at 18:02

Make a new template, add your loops, etc, without the HTML present in your desktop site. This is the only way to accomplish what you want.

share|improve this answer
    
Header and footer should be also dealt with, no? –  brasofilo Feb 13 '13 at 20:21
    
"Not have any of the standard Wordpress content around it" seemed like header and footer should be removed. Can the poster clarify? –  smithandteam Feb 15 '13 at 5:27
    
You should post the comment in the Question itself. Note that many times you need to use @username to address other user. But the author of the Question (or Answer) is always notified, depends on the situation. :::: Just in case: @spinlock, can you give the answerers some feedback? –  brasofilo Feb 15 '13 at 5:33
    
@smithandteam is correct in that I don't want to add WordPress' header and footer. FYI - the usecase is to show a dialog to mobile users and jquery-mobile was conflicting with the rest of the theme. My solution is to isolate the dialog and serve up a stripped down page with jquery-mobile to get the user's response and return to the rest of the site. –  spinlock Feb 15 '13 at 18:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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