background/font size change and remember

Here is how you can sett a cookie whit a variable: Now it saves for one day. $settings = $mybackground; setcookie(‘background’,$settings,time() + (86400)); // 86400 = 1 day Print it in the body like an img whit this: echo $_COOKIE[‘background’];

How to setcookie if is_page(‘page’) ? should I use add_action(‘init’) or there is another action?

template_redirect and wp (as the OP noted in comments) are good hooks to do this. But there’s a problem of logic in the sample code. I think it should be like: add_action( ‘template_redirect’, ‘cookie_redirect_wpse_113662’ ); function cookie_redirect_wpse_113662() { # No cookie set, let’s do it if( !isset( $_COOKIE[‘site_language’] ) ) set_cookie_wpse_113662( ‘ar’ ); # One … Read more

Prevent installation of style.css cookies and file caching

I expect that your theme has code similar to this in it: wp_enqueue_style( ‘themename-style’, get_stylesheet_uri() ); You need to alter this to have version information, like so: wp_enqueue_style( ‘themename-style’, get_stylesheet_uri(), array(), ‘1.0’ ); Where “1.0” is the version of the theme. Now, every time you alter that stylesheet, you need to update the version number. … Read more

Change in permalink structure made javascript cookie not work correctly

From comment: There is not enough information to answer your question. All your code is javascript, not PHP. Additionally, there is no function named “setCookie” or “getCookie” in javascript, and you don’t state what libraries you are using. The answer is most likely that your setCookie function is using the current page path (cookies have … Read more

How to set cookies to switch style sheets when a link is clicked and set it till another particular link is clicked?

You can use init action to set cookie, and other init action to read it. However due its a cookie… you will need also to check GET variable. add_action(‘init’, ‘is_it_mobile_or_desktop’, 1); function is_it_mobile_or_desktop(){ if (isset($_GET[‘site’]) && in_array($_GET[‘site’], array(‘mobile’, ‘desktop’)) ) { setcookie( ‘site’, $_GET[‘site’], time() – YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); } } add_action(‘init’, ‘who_am_i’, 2); … Read more

How to delete Passwrd Protected posts cookies when a user logged out from the site

The post password cookie is set with: setcookie( ‘wp-postpass_’ . COOKIEHASH, $hasher->HashPassword( wp_unslash( $_POST[‘post_password’] ) ), $expire, COOKIEPATH, COOKIE_DOMAIN, $secure ); in the wp-login.php file. We can then use the clear_auth_cookie hook, in the wp_clear_auth_cookie() function, to clear it on logout: /** * Clear the Post Password Cookie on logout. * * @link http://wordpress.stackexchange.com/a/198890/26350 */ … Read more

Disconnect automattically after X minutes

By default, the “Remember Me” checkbox makes you get remembered for 14 days. This is filterable though. add below code in your theme functions.php where 31556926 = 1 year in seconds This code will change that value: add_filter( ‘auth_cookie_expiration’, ‘keep_me_logged_in_for_1_year’ ); function keep_me_logged_in_for_1_year( $expirein ) { return 31556926; // 1 year in seconds }