Support » Plugin: Code Snippets » Can we use based on Template type specific?

  • Resolved Gulshan Kumar

    (@thegulshankumar)


    I would like to have easy way to execute code only for certain template such as Homepage, post, page, category,tag, like this.

    My requirement is to pass a HTTP header

    If homepage
    `
    cache-control: max-age:300;
    `

    Thanks & Regards,
    Gulshan

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hello,

    You can use WordPress template tags to work out which template is currently being viewed.

    For example, here’s a way to achieve what you describe in the question:

    add_action( 'template_redirect', function () {
    	if ( is_home() || is_single() || is_page() || is_category() || is_tag() ) {
    		header( 'Cache-control: max-age=300' );
    	}
    } );

    Thanks a lot dear. Much appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can we use based on Template type specific?’ is closed to new replies.