Return to Snippet

Revision: 10958
at January 19, 2009 17:14 by grosbouff

Initial Code
Plugin Name: first-visit-template
Description: Loads a welcome.php template in theme directory if it is the first visit (the function is not lauched if you're logged as admin), and writes a cookie so it's shown only once.
Author: G.Lachance
Author URI:
Credits: Based upon the "Welcome Visitor! Reloaded" plugin from  Alaeddin, which is largely based upon the original Welcome Visitor! plugin by Kaf (
which was released under the GNU General Public License.
Version: 1


//for testing your template, uncomment line 30.

function welcome_visitor_reloaded() {

	if(is_new_visitor()) {
		$tpl_file = TEMPLATEPATH . '/welcome.php';
		if ( file_exists($tpl_file) ) {

function is_new_visitor()

	//return true; //uncomment this for testing.
	global $visits;
	if (!is_admin())
		if (isset($_COOKIE['visits']))
			$visits = $_COOKIE['visits'] + 1;
			$visits = 1;
		$url = parse_url(get_option('home'));
		setcookie('visits', $visits, time()+60*60*24*365, $url['path'] . '/');
	else return false;

	return $visits == 1;

add_action('template_redirect', 'welcome_visitor_reloaded');


Initial URL

Initial Description

Initial Title
[PLUGIN] Wordpress specific template for first visit (and writes a cookie)

Initial Tags
plugin, template, wordpress

Initial Language