Support » Fixing WordPress » Add css class if visited the second page

  • [ Moderator note: moved to Fixing WordPress. Please do not use Developing With WordPress for these topics. ]

    Hi professionals,

    I would like to add a css class to body if a visitor go to the second or third etc. page of the website. Or vica versa: add class only on the first visited page. The goal is that I can distinguish the first visited page.

    Do you have any idea how can I solve this? Javascript? WP_SESSIONS?

    Very appreciate your help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @batyuvitez,

    You can use the Cookie for this kind of things and using the cookie I think you can achieve the functionality.

    Thanks,

    Thank you. WP_SESSIONS would also solve my problem?

    Moderator bcworkz

    (@bcworkz)

    You essentially wish to have a value created in one request be available to subsequent requests. There are several ways to do this, each has their pros and cons. Yes, PHP Session variables is one option, cookies another. There are also WP Transients, user meta, URL parameters, POST values, and maybe a few more I’ve forgotten or never knew.

    One thing that is important to establish is how do you determine if a subsequent request is for the same visit or it constitutes a new visit? The value that is maintained between requests might be a timestamp. If it’s older than some time period, consider the request a new visit. The time period is arbitrary, it could range from minutes to months. With shorter periods, it’ll be important to refresh the timestamp with every request. Some methods include an expiration time, so there is no need to pass a timestamp. The fact a value exists is enough.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.