Kalpit
Kalpit

Reputation: 4936

How to remove header and footer from particular post

i wondering how can i remove header and footer from the one particular post. i have searched around google and wordpress but i didn't get anything which can prevent header and footer to display.

i am using memberpress plugin and i am changing the design of registration form. here i am not able to use custom template also.

i know for page we can prevent to display some of the code for that page by using following code but need help on post.

 if(!is_page('1'))
     //not to display

any help?

Upvotes: 1

Views: 1881

Answers (2)

vrajesh
vrajesh

Reputation: 2942

There are two ways..

(1)create php file as 'single-PID.php' in your selected theme folder suppose that you added post and the post id is 18(remember post id is important) and on that you don't want header and footer. so

  • copy and paste single.php and u get 'single-copy.php' rename to 'single-18.php'(18 is post id).
  • now in single-18.php remove get_header() and get_footer().
  • now add below function in 'function.php' file :

    function my_single_template_by_post_id( $located_template ) {
        return locate_template( array( sprintf( "single-%d.php", absint( get_the_ID() ) ), $located_template ) );
    }
    add_filter( 'single_template', 'my_single_template_by_post_id' );
    
  • admin side ,select posts from menu ...click view on post that has id '18'

(2)create php file as 'page-PID.php' in your selected theme folder suppose that you added page and the page(save as post type 'page' in wp-post database table) id is 8(remember post id is important) and on that you don't want header and footer. so

  • copy and paste page.php and u get 'page-copy.php' rename to 'page-8.php'(8 is page id).
  • now in page-8.php remove get_header() and get_footer().
  • admin side ,select pages from menu ...click view link on page that has id '8'

Upvotes: 1

Avinash
Avinash

Reputation: 6174

You can use is_single function just like is_page.

http://codex.wordpress.org/Function_Reference/is_single

Copied from Codex:

is_single(); // When any single Post page is being displayed.

is_single('17'); // When Post 17 (ID) is being displayed.

is_single(17); // When Post 17 (ID) is being displayed. Integer parameter also works

Upvotes: 3

Related Questions