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
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.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'.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.