Returns the WPML language Code as a short code

This short code returns the current page’s WPML language code. As always register it first in Views if you want to use it with Toolset. Can be useful to display content depending on current language

/** 
 *Add ICL_LANGUAGE_CODE shortcode 
 */
        
function wpml_language_code_value_func() {
	$return = ICL_LANGUAGE_CODE;
	return $return;
	}   
add_shortcode('wpml_language_code_value', 'wpml_language_code_value_func');

Add Gravatar ShortCode with email attribute

This short code can be used to get the User’s Gravatar determining he’s / her’s email as attribute

/**
 * Add Gravatar Support for Views 
 */
function otgs_gravatar($atts) {
   return get_avatar( $atts['email'] );
}
add_shortcode('otgs-gravatar', 'otgs_gravatar');

Use it like this:
[otgs-gravatar email="user_email@site.com"]

Display menu depending on Login Status

Hides the “default” menu for non logged in users and instead displays a Custom Menu (in this case called “unlogged”)
The menu must of course be set up as a menu in Dashboard > Appearance A Menu, but not be displayed anywhere by default.

/**
 *Used to remove menu for non logged users and display custom menu instead 
 *Do NOT redecalre the menu LOGGED in users see, because, other wise he will see always the SAME menu (like in custom menus, he will see the default menu)
 */

function my_wp_nav_menu_args( $args = '' ) {

        if( !is_user_logged_in() ) {

            $args['menu'] = 'unlogged';

    }

        return $args;

}

    add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );

Hide every page but one if user is not logged in

This snippet allows “Members only” sites.

It redirects always to a custom PHP template (noaccess) if the user is not logged in, and obviously it will NOT redirect anywhere if the User access the custom template (noaccess).

Other wise a infinite loop would be generated.

/**
 *Used to redirect if not logged in
 */

function admin_redirect() {
    if ( !is_page('noaccess') && ! is_user_logged_in() ) {
    
        wp_redirect( home_url('/noaccess/') );
        exit;
    }
}
add_action('get_header', 'admin_redirect');