Shortcode to show usernamein WordPress

function show_loggedin_function( $atts ) {

	global $current_user, $user_login;
      	get_currentuserinfo();
	add_filter('widget_text', 'do_shortcode');
	if ($user_login) 
		return '<div class="mw-logged-in-info">Hallo ' . $current_user->display_name . ' <br><a href="https://vhe-shop2.wp8-demo.de/mein-konto/">Mein Konto</a> </div>';
	else
		return 'Sie haben noch kein Konto? <a href="/login/">Login / Registrieren</a>';
	
}
add_shortcode( 'show_loggedin_as', 'show_loggedin_function' );

Replace / Translate Text in WordPress

function multi_change_translate_text( $translated ) {
    $text       = array(
        'Old Text 1' => 'New Text 1',
        'Old Text 2' => 'New Text 2',
        'Old Text 3' => 'New Text 3',
    );
    $translated = str_ireplace( array_keys( $text ), $text, $translated );
    return $translated;
}
add_filter( 'gettext', 'multi_change_translate_text', 20 );

WordPress – Adding Link to Admin Sidebar

add_action( 'admin_menu', 'linked_url' );
function linked_url() {
add_menu_page( 'linked_url', 'External link', 'read', 'my_slug', '', 'dashicons-text', 1 );
}

add_action( 'admin_menu' , 'linkedurl_function' );
function linkedurl_function() {
global $menu;
$menu[1][2] = "http://www.example.com";
}

GeneratePress Elements in Adminbar

add_action('admin_bar_menu', 'add_toolbar_items', 100);
function add_toolbar_items($admin_bar){
    $admin_bar->add_menu( array(
        'id'    => 'mw-gp-elements',
        'title' => 'GP Elements',
        'href'  => '/wp-admin/edit.php?post_type=gp_elements',
        'meta'  => array(
            'title' => __('GP Elements'),
        ),
    ));
	
	$admin_bar->add_menu( array(
        'id'    => 'mw-gp-block',
        'parent' => 'mw-gp-elements',
        'title' => 'New GP Block',
        'href'  => '/wp-admin/post-new.php?post_type=gp_elements&element_type=block',
        'meta'  => array(
            'title' => __('New GP Block'),
            'class' => 'mw-gp-elements-adminbar'
        ),
    ));
	
	 $admin_bar->add_menu( array(
        'id'    => 'mw-gp-header',
        'parent' => 'mw-gp-elements',
        'title' => 'New GP Header',
        'href'  => '/wp-admin/post-new.php?post_type=gp_elements&element_type=header',
        'meta'  => array(
            'title' => __('New GP Header'),
            'class' => 'mw-gp-elements-adminbar'
        ),
    ));
	
	$admin_bar->add_menu( array(
        'id'    => 'mw-gp-hook',
        'parent' => 'mw-gp-elements',
        'title' => 'New GP Hook',
        'href'  => '/wp-admin/post-new.php?post_type=gp_elements&element_type=hook',
        'meta'  => array(
            'title' => __('New GP Hook'),
            'class' => 'mw-gp-elements-adminbar'
        ),
    ));
	
	$admin_bar->add_menu( array(
        'id'    => 'mw-gp-layout',
        'parent' => 'mw-gp-elements',
        'title' => 'New GP Layout',
        'href'  => '/wp-admin/post-new.php?post_type=gp_elements&element_type=layout',
        'meta'  => array(
            'title' => __('New GP Layout'),
            'class' => 'mw-gp-elements-adminbar'
        ),
    ));
}

Reusable Blocks in Admin Menu

function be_reusable_blocks_admin_menu() {
    add_menu_page( 'Reusable Blocks', 'Reusable Blocks', 'edit_posts', 'edit.php?post_type=wp_block', '', 'dashicons-editor-table', 22 );
}
add_action( 'admin_menu', 'be_reusable_blocks_admin_menu' );

Current Year Shortcode

add_shortcode( 'current_year', 'mw_current_year' );
function mw_current_year() {
    ob_start();
    echo date('Y');
    return ob_get_clean();
}

Shortcode

[current_year]
2022

Redirect after Login

For every user role except Admin

function my_login_redirect( $redirect_to, $request, $user ) {
    //is there a user to check?
    if ( isset( $user->roles ) && is_array( $user->roles ) ) {
        //check for admins
        if ( in_array( 'administrator', $user->roles ) ) {
            // redirect them to the default place
            return $redirect_to;
        } else {
            return home_url(); /* return home_url( '/members-only/' ); */
        }
    } else {
        return $redirect_to;
    }
}
 
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );