How to add another user to this remove_menu function?

Why not just add another if? function remove_menus(){ global $menu; global $current_user; get_currentuserinfo(); //check first user if($current_user->user_login == ‘user1’){ $restricted = array( __(‘Links’), __(‘Comments’), __(‘Appearance’), __(‘Plugins’), __(‘Profile’), __(‘Tools’), __(‘Settings’) ); end ($menu); while (prev($menu)){ $value = explode(‘ ‘,$menu[key($menu)][0]); if(in_array($value[0] != NULL?$value[0]:”” , $restricted)){unset($menu[key($menu)]);} } } //check second user if($current_user->user_login == ‘user2’){ $restricted = array( __(‘Links’), … Read more

What is the most efficient method for loading widgets in functions.php

Both are acceptable but not recommended. Use locate_template() instead because a child theme can overwrite the loaded file then. Example: $found = locate_template( ‘functions/my-custom-widget.php’, TRUE, TRUE ); The first TRUE tells WordPress not only to search for the file but to load it actually. The second makes it a require_once call. The function return the … Read more

How to set global variables in template page?

Anywhere in your script, you can define a global variable as follow: Using the superglobal $GLOBALS array. This array is predefined by PHP, and is available in all scopes. It’s an associate array, containing all global variables as a key-value pair. ie: the key will be the variable name, and value will be the value … Read more

Displaying Widgets

the_widget() is used to display a specific widget outside of a sidebar. To be honest, this function serves no valuable purpose as you need to hard code the widget $instance parameters, this means that you will need to manually change the code every time you need to change something. So much for dynamica. It would … Read more

Can I use require() function in a template file?

You are seeing this error because you are requireing the file with a relative path. As @Mark Kapulun pointed out in the comments you should not use relative paths when requireing files. Instead you want to be explicit and use absolute paths. Use get_template_directory() which returns the Absolute path to the directory of the current … Read more

CSS stylesheet not loading

I have tried to create WordPress theme using your functions.php, style.css and index.php and for me, the stylesheet is loading correctly. Please make sure you have added your header.php and footer.php for the theme. Please study some tutorials for theme development on WordPress.You can look at this link https://codex.wordpress.org/Theme_Development for detailed information.

How to detect first visit of a user?

No, there’s nothing in the core like that. You can set a cookie and do it simply enough (warning: untested code follows). <?php function is_first_time() { if (isset($_COOKIE[‘_wp_first_time’]) || is_user_logged_in()) { return false; } $domain = COOKIE_DOMAIN ? COOKIE_DOMAIN : $_SERVER[‘HTTP_HOST’]; // expires in 30 days. setcookie(‘_wp_first_time’, ‘1’, time() + (WEEK_IN_SECONDS * 4), “https://wordpress.stackexchange.com/”, $domain); … Read more

Adding body class when post contains a specific shortcode

I am doing something like this in one of my plugins: function my_body_class( $c ) { global $post; if( isset($post->post_content) && has_shortcode( $post->post_content, ‘your-shortcode’ ) ) { $c[] = ‘your-class’; } return $c; } add_filter( ‘body_class’, ‘my_body_class’ ); I’m not sure it was really necessary, but I probably can’t remove it now either. TheDeadMedic is … Read more

Redirect if not logged in?

The is_login_page() function is taken from here function is_login_page() { if ( $GLOBALS[‘pagenow’] === ‘wp-login.php’ && ! empty( $_REQUEST[‘action’] ) && $_REQUEST[‘action’] === ‘register’ ) return true; return false; } function my_redirect() { //if you have the page id of landing. I would tell you to use if( is_page(‘page id here’) instead //Don’t redirect if … Read more