Skip to main content
Cookie - Dynamic Shortcodes

Learn about the 'cookie' Dynamic Shortcode, for retrieving cookie values in WordPress.

Updated over 7 months ago

The Cookie Dynamic Shortcode is specifically tailored to access and return values stored in browser cookies, making it an essential tool for personalized user experiences on WordPress sites.

Syntax

{cookie:name}
  • name: The name of the cookie whose value is to be retrieved.

Examples

  1. Basic Cookie Retrieval

    {cookie:user_session}


    This example fetches the value of the 'user_session' cookie. It's useful for retrieving session-specific data for a user.

  2. Fallback Value

    {cookie:preferences?'Default settings'}


    Here, the shortcode attempts to retrieve the 'preferences' cookie. If the cookie is not found, it defaults to 'default_settings'.

  3. Within a Conditional Statement

    {if:{cookie:name} 
    'The Cookie exists'
    "The Cookie doesn't exists"
    }


    In this example, the shortcode checks if the 'name' cookie is not empty and displays a message accordingly.

Did this answer your question?