Quantcast
Channel: Wordpress Conditional Tags in Theme's function.php file - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Wordpress Conditional Tags in Theme's function.php file

$
0
0

I am trying to set HTTP response headers in my theme's function.php file, whereby i am trying to set expiry time as 6hours for single post page and 20 minutes for others.

I need to check the current accessed url is a single post page. For that i am using wordpress conditional tags and they are not working.

Here is my code:

function add_custom_http_headers($headers) {    $headers['Cache-Control'] = 'public';    $now = time();    if(is_single())        $then = gmstrftime("%a, %d %b %Y %H:%M:%S GMT", $now + 60*60*6);    else        $then = gmstrftime("%a, %d %b %Y %H:%M:%S GMT", $now + 20*60);    header("Expires: $then");    header("Last-Modified: ".gmstrftime("%a, %d %b %Y %H:%M:%S GMT", $now));    return $headers;}add_filter('wp_headers', 'add_custom_http_headers');

It seems like we cannot access the conditional tags where i am trying to use them. Please help me with a solution to find the current page type i.e. its a post page / home page / with/without using conditional tags in functions.php or any other suitable point of code to implement this header setting module.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images