I need to show some part of the page only once, based on cookies. The main problem that I can set cookies only in plugin, hooking init action.

I've read 20 pages of google, this site, asked 2 forums, but I still have this problem. Any help would be appreciated!

  • Chip Bennett is right - you can hook also via init. and can you specify exactly what is the problem of your "logic" ? I have used this method in functions.php more than once . functions.php and plugins are essentially the same, the only difference (as far as you concern) is the loading sequence .
    – krembo99
    Dec 13, 2011 at 5:19

2 Answers 2


Why do you think you can only hook into init via Plugin, rather than via the Theme?

The setup_theme hook, which fires when the Theme is setup, fires before the init hook. Thus, a Theme is perfectly capable of hooking into init.


Well, i'm not sure, that you get the idea.

I need to make some kind of a logic:

if (!isset($_COOKIE['mycookie'])
    echo 'Hi, anon!';
    setcookie('mycookie', 1, time()+60*60*24;

I can't make this functionality using plugins=(

  • Please do not use answers for discussion. Comment on answers or edit details into your original question. You might want to register on site so system recognizes you properly (otherwise you might be treated as different accounts and not have proper access to your question).
    – Rarst
    Oct 2, 2011 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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