Skip to content
All gists
Back to GitHub
Sign in
Sign up
Sign in
Sign up
{{ message }}
Instantly share code, notes, and snippets.
cameronjonesweb
/
jetpack-cookie-widget-without-widget-areas.php
Last active
Nov 18, 2018
Star
0
Fork
0
Star
Code
Revisions
4
Embed
What would you like to do?
Embed
Embed this gist in your website.
Share
Copy sharable link for this gist.
Clone via HTTPS
Clone with Git or checkout with SVN using the repository’s web address.
Learn more about clone URLs
Download ZIP
Display Jetpack's cookie notice on themes without a widget area
Raw
jetpack-cookie-widget-without-widget-areas.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
<?php
/**
* Class to add Jetpack's Cookie Notice Widget without needing a widget area
*/
class
Cameronjonesweb_Jetpack_Cookie_Notice
{
/**
* Instance of Jetpack's cookie notice widget.
*
* @var Jetpack_EU_Cookie_Law_Widget
*/
public
$
widget
;
/**
* Class constructor
*/
public
function
__construct
() {
add_action(
'widgets_init'
, [
$
this
,
'initialise_cookie_notice'
] );
add_action(
'wp_footer'
, [
$
this
,
'display_cookie_notice'
] );
}
/**
* Sets up Jetpack's cookie notice
*/
public
function
initialise_cookie_notice
() {
if
( class_exists(
'Jetpack_EU_Cookie_Law_Widget'
) ) {
$
this
->
widget
=
new
Jetpack_EU_Cookie_Law_Widget
();
add_action(
'wp_enqueue_scripts'
, [
$
this
->
widget
,
'enqueue_frontend_scripts'
] );
}
}
/**
* Displays the widget on the front end
*/
public
function
display_cookie_notice
() {
if
( class_exists(
'Jetpack_EU_Cookie_Law_Widget'
) ) {
$
args
= [
'before_widget'
=>
'<div class="widget_eu_cookie_law_widget">'
,
'after_widget'
=>
'</div>'
,
];
$
instance
= [];
$
this
->
widget
->
widget
(
$
args
,
$
instance
);
}
}
}
new
Cameronjonesweb_Jetpack_Cookie_Notice
();
Sign up for free
to join this conversation on GitHub
. Already have an account?
Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.