CookieYes Cookie Law Info Shortcodes

Below, you’ll find a detailed guide on how to add the Cookie Law Info Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Cookie Law Info Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Cookie Law Info Plugin and the shortcodes it provides:

Plugin Icon
CookieYes | GDPR Cookie Consent & Compliance Notice (CCPA Ready)

"CookieYes | GDPR Cookie Consent & Compliance Notice is a CCPA ready plugin that ensures your WordPress website complies with global privacy laws. It informs and gets consent from visitors about the use of cookies."

★★★★☆ (2506) Active Installs: 1000000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [wt_cli_ccpa_optout]
  • [delete_cookies]
  • [cookie_audit style="winter"]
  • [cookie_accept]
  • [cookie_reject]
  • [cookie_settings]
  • [cookie_link]
  • [cookie_button]
  • [cookie_after_accept]
  • [user_consent_state]
  • [webtoffee_powered_by]
  • [cookie_close]
  • [wt_cli_manage_consent]
  • [cookie_button]

Cookie Law Info [wt_cli_ccpa_optout] Shortcode

The Cookie Law Info shortcode ‘wt_cli_ccpa_optout’ is designed to handle user opt-out requests under the CCPA law. This shortcode generates a checkbox or link, allowing users to opt-out of having their personal information sold. The text and color of the opt-out element can be customized. If CCPA is not enabled, the shortcode returns an empty string.

Shortcode: [wt_cli_ccpa_optout]

Examples and Usage

Basic example – Show a CCPA opt-out checkbox with default text and color

[wt_cli_ccpa_optout /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wt_cli_ccpa_optout] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wt_cli_ccpa_optout', array( $this, 'wt_cli_ccpa_optout_callback' ) );

Shortcode PHP function:

function wt_cli_ccpa_optout_callback() {

		$cookie_options  = Cookie_Law_Info::get_settings();
		$this->ccpa_text = Cookie_Law_Info::sanitise_settings( 'button_6_text', ( isset( $cookie_options['button_6_text'] ) ? $cookie_options['button_6_text'] : 'Do not sell my personal information' ) );

		$ccpa_data    = '';
		$ccpa_enabled = $this->ccpa_enabled;
		$ccpa_as_link = $this->ccpa_as_link;
		$ccpa_text    = $this->ccpa_text;
		$ccpa_colour  = $this->ccpa_link_colour;
		if ( $ccpa_enabled === false ) {
			return '';
		}
		if ( $ccpa_as_link === false ) {

			$ccpa_data = '<span class="wt-cli-form-group wt-cli-custom-checkbox wt-cli-ccpa-checkbox"><input type="checkbox" id="wt-cli-ccpa-opt-out" class="wt-cli-ccpa-opt-out wt-cli-ccpa-opt-out-checkbox" ><label for="wt-cli-ccpa-opt-out" style="color:' . esc_attr( $ccpa_colour ) . ';" >' . esc_html( $ccpa_text ) . '</label></span>';

		} else {
			$ccpa_data = '<a style="color:' . esc_attr( $ccpa_colour ) . ';" class="wt-cli-ccpa-opt-out">' . esc_html( $ccpa_text ) . '</a>';
		}
		return $ccpa_data;
	}

Code file location:

cookie-law-info/cookie-law-info/legacy/admin/modules/ccpa/ccpa.php

Cookie Law Info [delete_cookies] Shortcode

The ‘Delete Cookies’ shortcode from the Cookie Law Info plugin is designed to create a clickable link for users to delete cookies. This shortcode generates a link with the text “Delete Cookies”. Users can customize this text. When clicked, it removes all cookies stored by the website.

Shortcode: [delete_cookies]

Examples and Usage

Basic example – Here we use the shortcode to display a link with the default text “Delete Cookies”.

[delete_cookies /]

Advanced examples

Using the shortcode to display a link to delete cookies with custom text. This provides more flexibility as you can customize the text according to your website’s theme or language.

[delete_cookies text="Remove Cookies" /]

Another example of using the shortcode to display a link to delete cookies with a different custom text. It demonstrates the flexibility of shortcode usage in customizing user interface elements.

[delete_cookies text="Clear Cookies" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [delete_cookies] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'delete_cookies', array( $this, 'cookielawinfo_delete_cookies_shortcode' ) ); // a shortcode [delete_cookies (text="Delete Cookies")]

Shortcode PHP function:

function cookielawinfo_delete_cookies_shortcode( $atts ) {

		$atts = shortcode_atts(
			array(
				'text' => __( 'Delete Cookies', 'cookie-law-info' ),
			),
			$atts,
			'delete_cookies'
		);
		return '<a href="" class="cookielawinfo-cookie-delete">' . esc_attr( $atts['text'] ) . '</a>';
	}

Code file location:

cookie-law-info/cookie-law-info/legacy/public/modules/shortcode/shortcode.php

Cookie Law Info [cookie_audit style=”winter”] Shortcode

The ‘cookie_audit’ shortcode from the Cookie Law Info plugin generates a table detailing all cookies used on your site. It includes columns for cookie type, duration, and description. The plugin allows customization of the table style, columns to display, and the category of cookies to include. It also supports WPML for multilingual sites.

Shortcode: [cookie_audit style="winter"]

Parameters

Here is a list of all possible cookie_audit style=”winter” shortcode parameters and attributes:

  • style – Defines the table style, default is “classic”.
  • not_shown_message – Message displayed when no cookies are found.
  • columns – Defines displayed table columns, default shows “cookie,type,duration,description”.
  • heading – Optional heading for the cookie audit table.
  • category – Filters the table to show cookies from a specific category.

Examples and Usage

Basic example – A simple usage of the shortcode that displays a cookie audit table with the classic style.

[cookie_audit style="classic"]

Advanced examples

Using the shortcode to display a cookie audit table with the winter style and a specific category of cookies. The table will only display cookies that belong to the specified category.

[cookie_audit style="winter" category="necessary"]

Using the shortcode to display a custom cookie audit table. This table will only display the cookie’s name and description. It will also display a custom message when no cookies are found.

[cookie_audit style="classic" columns="cookie,description" not_shown_message="No cookies found."] 

Using the shortcode to display a cookie audit table with a heading. The heading will be displayed at the top of the table.

[cookie_audit style="classic" heading="Our Cookies"]

PHP Function Code

In case you have difficulties debugging what causing issues with [cookie_audit style="winter"] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'cookie_audit', array( $this, 'cookielawinfo_table_shortcode' ) );           // a shortcode [cookie_audit style="winter"]

Shortcode PHP function:

function cookielawinfo_table_shortcode( $atts ) {

		/** RICHARDASHBY EDIT: only add CSS if table is being used */
		wp_enqueue_style( $this->plugin_name . '-table' );
		/** END EDIT */
		$atts    = shortcode_atts(
			array(
				'style'             => 'classic',
				'not_shown_message' => '',
				'columns'           => 'cookie,type,duration,description',
				'heading'           => '',
				'category'          => '',
			),
			$atts,
			'cookie_audit'
		);
		$columns = array_filter( array_map( 'trim', explode( ',', $atts['columns'] ) ) );
		$posts   = array();
		$args    = array(
			'post_type'      => CLI_POST_TYPE,
			/** 28/05/2013: Changing from 10 to 50 to allow longer tables of cookie data */
			'posts_per_page' => 50,
			'tax_query'      => array(),
			'order'          => 'ASC',
			'orderby'        => 'title',
		);
		global $sitepress;
		$is_wpml_enabled = false;
		if ( function_exists( 'icl_object_id' ) && $sitepress ) {
			$args['suppress_filters'] = false;
			$is_wpml_enabled          = true;
		}
		$category = isset( $atts['category'] ) ? $atts['category'] : '';
		if ( isset( $category ) && $category != '' ) {
			$wpml_default_lang = 'en';
			$wpml_current_lang = 'en';
			$term              = false;
			if ( $is_wpml_enabled ) {
				$wpml_default_lang = $sitepress->get_default_language();
				$wpml_current_lang = ICL_LANGUAGE_CODE;
				if ( $wpml_default_lang != $wpml_current_lang ) {
					$sitepress->switch_lang( $wpml_default_lang ); // switching to default lang
					$term = get_term_by( 'slug', $category, 'cookielawinfo-category' ); // original term
					$sitepress->switch_lang( $wpml_current_lang ); // revert back to current lang
					if ( ! $term ) {
						$term = get_term_by( 'slug', $category, 'cookielawinfo-category' ); // current lang term
					}
				} else {
					$term = get_term_by( 'slug', $category, 'cookielawinfo-category' );
				}
			} else {
				$term = get_term_by( 'slug', $category, 'cookielawinfo-category' );
			}
			if ( $term ) {
				$args['tax_query'][] = array(
					'taxonomy'         => 'cookielawinfo-category',
					'terms'            => $term->term_id,
					'include_children' => false,
				);
				$posts               = get_posts( $args ); // only return posts if term available
			}
		} else {
			$posts = get_posts( $args );
		}
		$ret = '<table class="cookielawinfo-row-cat-table cookielawinfo-' . esc_attr( $atts['style'] ) . '"><thead><tr>';
		if ( in_array( 'cookie', $columns ) ) {
			$ret .= '<th class="cookielawinfo-column-1">' . __( 'Cookie', 'cookie-law-info' ) . '</th>';
		}
		if ( in_array( 'type', $columns ) ) {
			$ret .= '<th class="cookielawinfo-column-2">' . __( 'Type', 'cookie-law-info' ) . '</th>';
		}
		if ( in_array( 'duration', $columns ) ) {
			$ret .= '<th class="cookielawinfo-column-3">' . __( 'Duration', 'cookie-law-info' ) . '</th>';
		}
		if ( in_array( 'description', $columns ) ) {
			$ret .= '<th class="cookielawinfo-column-4">' . __( 'Description', 'cookie-law-info' ) . '</th>';
		}
		$ret  = apply_filters( 'cli_new_columns_to_audit_table', $ret );
		$ret .= '</tr>';
		$ret .= '</thead><tbody>';

		if ( ! $posts ) {
			$ret .= '<tr class="cookielawinfo-row"><td colspan="4" class="cookielawinfo-column-empty">' . esc_html( $atts['not_shown_message'] ) . '</td></tr>';
		}

		// Get custom fields:
		if ( $posts ) {
			foreach ( $posts as $post ) {
				$custom          = get_post_custom( $post->ID );
				$cookie_type     = ( isset( $custom['_cli_cookie_type'][0] ) ) ? esc_html( sanitize_text_field( $custom['_cli_cookie_type'][0] ) ) : '';
				$cookie_duration = ( isset( $custom['_cli_cookie_duration'][0] ) ) ? esc_html( sanitize_text_field( $custom['_cli_cookie_duration'][0] ) ) : '';
				$ret            .= '<tr class="cookielawinfo-row">';
				if ( in_array( 'cookie', $columns ) ) {
					$ret .= '<td class="cookielawinfo-column-1">' . esc_html( sanitize_text_field( $post->post_title ) ) . '</td>';
				}
				if ( in_array( 'type', $columns ) ) {
					$ret .= '<td class="cookielawinfo-column-2">' . esc_html( $cookie_type ) . '</td>';
				}
				if ( in_array( 'duration', $columns ) ) {
					$ret .= '<td class="cookielawinfo-column-3">' . esc_html( $cookie_duration ) . '</td>';
				}
				if ( in_array( 'description', $columns ) ) {
					$ret .= '<td class="cookielawinfo-column-4">' . wp_kses_post( $post->post_content ) . '</td>';
				}
				$ret  = apply_filters( 'cli_new_column_values_to_audit_table', $ret, $custom );
				$ret .= '</tr>';
			}
		}
		$ret .= '</tbody></table>';
		if ( count( $posts ) > 0 ) {
			if ( $atts['heading'] != '' ) {
				$ret = '<p>' . esc_html( __( $atts['heading'], 'cookie-law-info' ) ) . '</p>' . $ret;
			}
		}
		if ( '' === $atts['not_shown_message'] && empty( $posts ) ) {
			$ret = '';
		}
		return $ret;
	}

Code file location:

cookie-law-info/cookie-law-info/legacy/public/modules/shortcode/shortcode.php

Cookie Law Info [cookie_accept] Shortcode

The Cookie Law Info plugin shortcode, ‘cookie_accept’, is used to generate a customizable ‘Accept’ button for cookie consent on a website. The shortcode allows customization of the button’s color and margin. By default, it sets the button color to green and does not apply any margin. However, these attributes can be modified according to user preference. The generated button is compliant with accessibility standards, featuring a role attribute and a tabindex. It also includes a ‘data-cli_action’ attribute set to ‘accept’, which triggers the acceptance of cookies when the button is clicked.

Shortcode: [cookie_accept]

Parameters

Here is a list of all possible cookie_accept shortcode parameters and attributes:

  • colour – Sets the colour of the accept button
  • margin – Specifies the margin around the accept button

If no params are used in the shortcode, the accept button will default to green with no specified margin. This means the button will adopt the default margin styles from your website’s CSS.

Examples and Usage

Basic example – A simple usage of the ‘cookie_accept’ shortcode without any additional parameters. By default, it will generate a green ‘Accept’ button.

[cookie_accept /]

Advanced examples

Changing the color of the ‘Accept’ button to red. This is achieved by using the ‘colour’ parameter within the shortcode.

[cookie_accept colour="red" /]

Setting a specific margin for the ‘Accept’ button. This is done by using the ‘margin’ parameter within the shortcode. The value of the margin should be specified in CSS format.

[cookie_accept margin="10px 20px" /]

Combining both the ‘colour’ and ‘margin’ parameters to customize the ‘Accept’ button. This will generate a red ‘Accept’ button with a specific margin.

[cookie_accept colour="red" margin="10px 20px" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [cookie_accept] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'cookie_accept', array( $this, 'cookielawinfo_shortcode_accept_button' ) );      // a shortcode [cookie_accept (colour="red")]

Shortcode PHP function:

function cookielawinfo_shortcode_accept_button( $atts ) {
		$atts          = shortcode_atts(
			array(
				'colour' => 'green',
				'margin' => '',
			),
			$atts,
			'cookie_accept'
		);
		$defaults      = Cookie_Law_Info::get_default_settings( 'button_1_text' );
		$settings      = wp_parse_args( Cookie_Law_Info::get_settings(), $defaults );
		$button_1_text = __( $settings['button_1_text'], 'cookie-law-info' );
		$margin_style  = $atts['margin'] != '' ? ' style="margin:' . esc_attr( $atts['margin'] ) . ';" ' : '';
		return '<a role="button" tabindex="0" class="cli_action_button cli-accept-button medium cli-plugin-button ' . esc_attr( $atts['colour'] ) . '" data-cli_action="accept"' . $margin_style . '>' . esc_html( stripslashes( $button_1_text ) ) . '</a>';
	}

Code file location:

cookie-law-info/cookie-law-info/legacy/public/modules/shortcode/shortcode.php

Cookie Law Info [cookie_reject] Shortcode

The ‘cookie_reject’ shortcode from the Cookie Law Info plugin is designed to generate a cookie rejection button. The button’s appearance and functionality are customizable via shortcode attributes. It can be styled with margins and colors, and its action can be set to open a URL or serve as a button. The shortcode ensures the button adheres to accessibility standards by adding the necessary roles and attributes.

Shortcode: [cookie_reject]

Examples and Usage

Basic example – A simple usage of the shortcode to display the cookie reject button with no additional parameters.

[cookie_reject /]

Advanced examples

Using the shortcode with a margin parameter. This will display the cookie reject button with a specific margin around it. The margin value should be provided in valid CSS format.

[cookie_reject margin="10px 20px 30px 40px"/]

Using the shortcode with a color parameter. This will display the cookie reject button in the specified color. The color value should be a valid CSS color.

[cookie_reject color="red"/]

Combining multiple parameters. This will display the cookie reject button with the specified margin and color.

[cookie_reject margin="10px 20px 30px 40px" color="red"/]

PHP Function Code

In case you have difficulties debugging what causing issues with [cookie_reject] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'cookie_reject', array( $this, 'cookielawinfo_shortcode_reject_button' ) );      // a shortcode [cookie_reject (colour="red")]

Shortcode PHP function:

function cookielawinfo_shortcode_reject_button( $atts ) {
		$atts = shortcode_atts(
			array(
				'margin' => '',
			),
			$atts,
			'cookie_reject'
		);

		$margin_style = $atts['margin'] != '' ? ' style="margin:' . esc_attr( $atts['margin'] ) . ';" ' : '';

		$defaults = Cookie_Law_Info::get_default_settings();
		$settings = wp_parse_args( Cookie_Law_Info::get_settings(), $defaults );

		$classr = '';
		if ( $settings['button_3_as_button'] ) {
			$classr = ' class="' . esc_attr( $settings['button_3_button_size'] ) . ' cli-plugin-button cli-plugin-main-button cookie_action_close_header_reject cli_action_button wt-cli-reject-btn"';
		} else {
			$classr = ' class="cookie_action_close_header_reject cli_action_button wt-cli-reject-btn" ';
		}
		$url_reject = ( $settings['button_3_action'] == 'CONSTANT_OPEN_URL' && $settings['button_3_url'] != '#' ) ? 'href="' . esc_url( $settings['button_3_url'] ) . '"' : "role='button' tabindex='0'";
		$link_tag   = '';
		$link_tag  .= '<a ' . $url_reject . ' id="' . esc_attr( Cookie_Law_Info_Public::cookielawinfo_remove_hash( $settings['button_3_action'] ) ) . '" ';
		$link_tag  .= ( $settings['button_3_new_win'] ) ? 'target="_blank" ' : '';
		$link_tag  .= $classr . '  data-cli_action="reject"' . $margin_style . '>' . esc_html( stripslashes( __( $settings['button_3_text'], 'cookie-law-info' ) ) ) . '</a>';
		return $link_tag;
	}

Code file location:

cookie-law-info/cookie-law-info/legacy/public/modules/shortcode/shortcode.php

Cookie Law Info [cookie_settings] Shortcode

The Cookie Law Info shortcode is used to create a customizable settings button for cookie preferences. This shortcode allows you to set margins and button size. It also enables you to specify whether the button opens a new window or not. The button’s link and action are also customizable.

Shortcode: [cookie_settings]

Examples and Usage

Basic example – A shortcode that invokes the ‘cookie_settings’ function without any specific parameters.

[cookie_settings /]

Advanced examples

Adjusting the margin of the settings button using the ‘margin’ attribute. This shortcode will add a margin around the settings button according to the specified value.

[cookie_settings margin="10px" /]

Another advanced example could be using the shortcode to display the cookie settings button with a custom margin and a specific button size. The button size will be applied only if the ‘button_4_as_button’ setting is enabled.

[cookie_settings margin="20px" button_4_button_size="large" /]

Please note that the actual output of the shortcode depends on the current settings of the Cookie Law Info plugin. The ‘button_4_as_button’ and ‘button_4_button_size’ settings are not directly set via the shortcode, but are fetched from the plugin’s settings.

PHP Function Code

In case you have difficulties debugging what causing issues with [cookie_settings] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'cookie_settings', array( $this, 'cookielawinfo_shortcode_settings_button' ) );      // a shortcode [cookie_settings]

Shortcode PHP function:

function cookielawinfo_shortcode_settings_button( $atts ) {
		$atts                         = shortcode_atts(
			array(
				'margin' => '',
			),
			$atts,
			'cookie_settings'
		);
		$margin_style                 = $atts['margin'] != '' ? ' style="margin:' . esc_attr( $atts['margin'] ) . ';" ' : '';
		$defaults                     = Cookie_Law_Info::get_default_settings();
		$settings                     = wp_parse_args( Cookie_Law_Info::get_settings(), $defaults );
		$settings['button_4_url']     = '#';
		$settings['button_4_action']  = '#cookie_action_settings';
		$settings['button_4_new_win'] = false;
		$classr                       = '';
		if ( $settings['button_4_as_button'] ) {
			$classr = ' class="' . esc_attr( $settings['button_4_button_size'] ) . ' cli-plugin-button cli-plugin-main-button cli_settings_button"';
		} else {
			$classr = ' class="cli_settings_button"';
		}

		// adding custom style
		$url_s     = ( $settings['button_4_action'] == 'CONSTANT_OPEN_URL' && $settings['button_4_url'] != '#' ) ? 'href="' . esc_url( $settings['button_4_url'] ) . '"' : "role='button' tabindex='0'";
		$link_tag  = '';
		$link_tag .= '<a ' . $url_s;
		$link_tag .= ( $settings['button_4_new_win'] ) ? ' target="_blank" ' : '';
		$link_tag .= $classr . '' . $margin_style . '>' . esc_html( stripslashes( $settings['button_4_text'] ) ) . '</a>';
		return $link_tag;
	}

Code file location:

cookie-law-info/cookie-law-info/legacy/public/modules/shortcode/shortcode.php

Cookie Law Info [cookie_link] Shortcode

The Cookie Law Info plugin shortcode, ‘cookie_link’, is used to generate a more info link. This link redirects users to a page with detailed cookie policy. The PHP function ‘cookielawinfo_shortcode_more_link’ renders the button for this link. It uses the DRY code principle to avoid repetition, enhancing code readability and maintenance.

Shortcode: [cookie_link]

Examples and Usage

Basic example – A simple use of the shortcode to display the cookie information link.

[cookie_link /]

Advanced examples

Using the shortcode to display the cookie information link with additional parameters. In this case, we’re specifying the text and URL for the link, and adding a custom class to it.

[cookie_link text="Privacy Policy" url="http://example.com/privacy-policy/" class="custom-class" /]

Using the shortcode to display the cookie information link with a button. We’re specifying the button text, link, and adding a custom class to the button.

[cookie_link button="Accept Cookies" url="http://example.com/accept-cookies/" class="custom-button-class" /]

These examples demonstrate the flexibility of the [cookie_link] shortcode, allowing you to customize the displayed link or button to fit your website’s design and content needs.

PHP Function Code

In case you have difficulties debugging what causing issues with [cookie_link] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'cookie_link', array( $this, 'cookielawinfo_shortcode_more_link' ) );            // a shortcode [cookie_link]

Shortcode PHP function:

function cookielawinfo_shortcode_more_link( $atts ) {
		return $this->cookielawinfo_shortcode_button_DRY_code( 'button_2', $atts );
	}

Code file location:

cookie-law-info/cookie-law-info/legacy/public/modules/shortcode/shortcode.php

Cookie Law Info [cookie_button] Shortcode

The Cookie Law Info shortcode is a tool for creating a customizable cookie acceptance button on your WordPress site. This shortcode allows users to define the margin of the button, its class, and its action. If the button’s action is not a URL, it won’t use a URL. The button can open a new window if specified. The text on the button can be customized, making it versatile for any site.

Shortcode: [cookie_button]

Examples and Usage

Basic example – A shortcode for displaying the main cookie acceptance button with default settings.

[cookie_button /]

PHP Function Code

In case you have difficulties debugging what causing issues with [cookie_button] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'cookie_button', array( $this, 'cookielawinfo_shortcode_main_button' ) );        // a shortcode [cookie_button]

Shortcode PHP function:

function cookielawinfo_shortcode_main_button( $atts ) {
		$atts         = shortcode_atts(
			array(
				'margin' => '',
			),
			$atts,
			'cookie_button'
		);
		$margin_style = $atts['margin'] != '' ? ' margin:' . esc_attr( $atts['margin'] ) . '; ' : '';

		$defaults = Cookie_Law_Info::get_default_settings();
		$settings = wp_parse_args( Cookie_Law_Info::get_settings(), $defaults );
		$class    = '';
		if ( $settings['button_1_as_button'] ) {
			$class = ' class="' . esc_attr( $settings['button_1_button_size'] ) . ' cli-plugin-button cli-plugin-main-button cookie_action_close_header cli_action_button wt-cli-accept-btn"';
		} else {
			$class = ' class="cli-plugin-main-button cookie_action_close_header cli_action_button wt-cli-accept-btn" ';
		}

		// If is action not URL then don't use URL!
		$url       = ( $settings['button_1_action'] == 'CONSTANT_OPEN_URL' && $settings['button_1_url'] != '#' ) ? 'href="' . esc_url( $settings['button_1_url'] ) . '"' : "role='button' tabindex='0'";
		$link_tag  = '<a ' . $url . ' data-cli_action="accept" id="' . esc_attr( Cookie_Law_Info_Public::cookielawinfo_remove_hash( $settings['button_1_action'] ) ) . '" ';
		$link_tag .= ( $settings['button_1_new_win'] ) ? 'target="_blank" ' : '';
		$link_tag .= $class . ' style="display:inline-block; ' . $margin_style . '">' . esc_html( stripslashes( __( $settings['button_1_text'], 'cookie-law-info' ) ) ) . '</a>';

		return $link_tag;
	}

Code file location:

cookie-law-info/cookie-law-info/legacy/public/modules/shortcode/shortcode.php

Cookie Law Info [cookie_after_accept] Shortcode

The ‘cookie_after_accept’ shortcode is a part of the Cookie Law Info plugin. It checks if a user has accepted the cookie policy. If the ‘viewed_cookie_policy’ cookie is set to ‘yes’, it returns the content. If not, it returns an empty string.

Shortcode: [cookie_after_accept]

Examples and Usage

Basic example – A simple usage of the ‘cookie_after_accept’ shortcode. It will display the content only if the user has accepted the cookie policy.

[cookie_after_accept] Your content here [/cookie_after_accept]

Advanced examples

Embedding a contact form within the ‘cookie_after_accept’ shortcode. This will only display the contact form if the user has accepted the cookie policy.

[cookie_after_accept] [contact-form-7 id="123" title="Contact form 1"] [/cookie_after_accept]

Using the ‘cookie_after_accept’ shortcode within a text block. This will only display the text block if the user has accepted the cookie policy.

[cookie_after_accept] 

Your paragraph here

[/cookie_after_accept]

Note: The ‘cookie_after_accept’ shortcode does not accept any parameters. The content displayed is solely dependent on the user’s cookie acceptance status.

PHP Function Code

In case you have difficulties debugging what causing issues with [cookie_after_accept] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'cookie_after_accept', array( $this, 'cookie_after_accept_shortcode' ) );

Shortcode PHP function:

function cookie_after_accept_shortcode( $atts = array(), $content = '' ) {
		if ( isset( $_COOKIE['viewed_cookie_policy'] ) && $_COOKIE['viewed_cookie_policy'] == 'yes' ) {
			return $content;
		} else {
			return '';
		}
	}

Code file location:

cookie-law-info/cookie-law-info/legacy/public/modules/shortcode/shortcode.php

Cookie Law Info [user_consent_state] Shortcode

The ‘user_consent_state’ shortcode from the Cookie Law Info plugin displays the current user’s cookie consent status on the website. This shortcode checks if the user has accepted, rejected, or not yet given their consent to cookies.

Shortcode: [user_consent_state]

Examples and Usage

Basic example – Displaying the user’s consent state

[user_consent_state /]

PHP Function Code

In case you have difficulties debugging what causing issues with [user_consent_state] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'user_consent_state', array( $this, 'user_consent_state_shortcode' ) );

Shortcode PHP function:

function user_consent_state_shortcode( $atts = array() ) {
		add_action( 'wp_footer', array( $this, 'manage_user_consent_jsblock' ), 15 );

		$html = '<div class="cli_user_consent_state">' . __( 'Your current state:', 'cookie-law-info' );
		if ( isset( $_COOKIE['viewed_cookie_policy'] ) ) {
			if ( $_COOKIE['viewed_cookie_policy'] == 'yes' ) {
				$html .= ' ' . __( 'Consent accepted.', 'cookie-law-info' );
			} else {
				$html .= ' ' . __( 'Consent rejected.', 'cookie-law-info' );
			}
		} else // no conset given
		{
			$html .= ' ' . __( 'No consent given.', 'cookie-law-info' );
		}
		$html .= ' <a class="cli_manage_current_consent" style="cursor:pointer;text-decoration:underline;">' . __( 'Manage your consent.', 'cookie-law-info' ) . '</a> </div>';
		return $html;
	}

Code file location:

cookie-law-info/cookie-law-info/legacy/public/modules/shortcode/shortcode.php

Cookie Law Info [webtoffee_powered_by] Shortcode

The WebToffee Powered By shortcode is a custom WordPress shortcode that adds a stylized footer text crediting WebToffee. This PHP function returns a paragraph with specific style attributes and a hyperlink to WebToffee’s website.

Shortcode: [webtoffee_powered_by]

Examples and Usage

Basic example – A simple instance of the WebToffee powered-by shortcode. This will display a ‘Powered By WebToffee’ message at the bottom of your content.

[webtoffee_powered_by /]

PHP Function Code

In case you have difficulties debugging what causing issues with [webtoffee_powered_by] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'webtoffee_powered_by', array( $this, 'wf_powered_by' ) );

Shortcode PHP function:

function wf_powered_by() {
		return '<p class="powered_by_p" style="width:100% !important; display:block !important; color:#333; clear:both; font-style:italic !important; font-size:12px !important; margin-top:15px !important;">Powered By <a href="https://www.webtoffee.com/" class="powered_by_a" style="color:#333; font-weight:600 !important; font-size:12px !important;">WebToffee</a></p>';
	}

Code file location:

cookie-law-info/cookie-law-info/legacy/public/modules/shortcode/shortcode.php

Cookie Law Info [cookie_close] Shortcode

The ‘cookie_close’ shortcode is part of the Cookie Law Info plugin. It generates a close button for the cookie consent bar. The PHP function ‘cookielawinfo_shortcode_close_button’ creates a clickable ‘X’ button. On clicking, it triggers the action to accept cookies and close the bar.

Shortcode: [cookie_close]

Examples and Usage

Basic example – A simple usage of the shortcode to close the cookie bar.

[cookie_close /]

PHP Function Code

In case you have difficulties debugging what causing issues with [cookie_close] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'cookie_close', array( $this, 'cookielawinfo_shortcode_close_button' ) );        // a shortcode [close_button]

Shortcode PHP function:

function cookielawinfo_shortcode_close_button() {
		$styles = '';
		return '<a style="' . esc_attr( $styles ) . '" aria-label="' . __( 'Close the cookie bar', 'cookie-law-info' ) . '" data-cli_action="accept" class="wt-cli-element cli_cookie_close_button" title="' . __( 'Close and Accept', 'cookie-law-info' ) . '">×</a>';
	}

Code file location:

cookie-law-info/cookie-law-info/legacy/public/modules/shortcode/shortcode.php

Cookie Law Info [wt_cli_manage_consent] Shortcode

The ‘wt_cli_manage_consent’ shortcode from Cookie Law Info plugin is used to manage user consent for cookies. It fetches the settings and displays a consent link.

Shortcode: [wt_cli_manage_consent]

Examples and Usage

Basic example – Displays the link to manage cookie consent.

[wt_cli_manage_consent /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wt_cli_manage_consent] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'wt_cli_manage_consent', array( $this, 'manage_consent' ) );

Shortcode PHP function:

function manage_consent() {
		if ( ! $this->cookie_options ) {
			$this->cookie_options = Cookie_Law_Info::get_settings();
		}
		$manage_consent_link = '';
		$manage_consent_text = ( isset( $this->cookie_options['showagain_text'] ) ? $this->cookie_options['showagain_text'] : '' );
		$manage_consent_link = '<a class="wt-cli-manage-consent-link">' . esc_html( $manage_consent_text ) . '</a>';

		return $manage_consent_link;
	}

Code file location:

cookie-law-info/cookie-law-info/legacy/public/modules/shortcode/shortcode.php

Cookie Law Info [cookie_button] Shortcode

The ‘cookie_accept_all’ shortcode from the Cookie Law Info plugin generates an ‘Accept All’ button. This button allows users to consent to all cookies at once. The PHP code defines the button’s appearance and behavior. It checks if the button should be displayed as a button or a link, assigns the appropriate CSS class, and sets the URL or role attribute. It also checks if the button should open a new window and adds the button text. The generated link tag is returned and displayed on the website.

Shortcode: [cookie_button]

Examples and Usage

Basic example – A simple usage of the shortcode to display the “Accept All” button with default settings.

[cookie_accept_all /]

PHP Function Code

In case you have difficulties debugging what causing issues with [cookie_button] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'cookie_accept_all', array( $this, 'accept_all_button' ) );      // a shortcode [cookie_button]

Shortcode PHP function:

function accept_all_button() {

		$defaults = Cookie_Law_Info::get_default_settings();
		$settings = wp_parse_args( Cookie_Law_Info::get_settings(), $defaults );
		$class    = '';
		if ( $settings['button_7_as_button'] ) {
			$class = ' class="wt-cli-element' . ' ' . esc_attr( $settings['button_7_button_size'] ) . ' cli-plugin-button wt-cli-accept-all-btn cookie_action_close_header cli_action_button"';
		} else {
			$class = ' class="wt-cli-element cli-plugin-main-button wt-cli-accept-all-btn cookie_action_close_header cli_action_button" ';
		}
		$url = ( $settings['button_7_action'] == 'CONSTANT_OPEN_URL' && $settings['button_7_url'] != '#' ) ? 'href="' . esc_url( $settings['button_7_url'] ) . '"' : "role='button'";

		$link_tag  = '<a id="wt-cli-accept-all-btn" tabindex="0" ' . $url . ' data-cli_action="accept_all" ';
		$link_tag .= ( $settings['button_7_new_win'] ) ? ' target="_blank" ' : '';
		$link_tag .= $class . ' >' . esc_html( stripslashes( $settings['button_7_text'] ) ) . '</a>';
		return $link_tag;
	}

Code file location:

cookie-law-info/cookie-law-info/legacy/public/modules/shortcode/shortcode.php

Conclusion

Now that you’ve learned how to embed the Cookie Law Info Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *