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' );
Snippets
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 );
Display Pods Custom Field
<php echo get_post_meta (get_the_ID(), 'auto', true); ?>
GeneratePress – adding smooth scroll to all anchor links
add_filter( 'generate_smooth_scroll_elements', function( $elements ) {
$elements[] = 'a[href*="#"]';
return $elements;
} );
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 Excerpt Shortcode
function db_page_hero_excerpt() {
ob_start();
global $post;
if ( has_excerpt( $post->ID ) ) {
?>
<div class="page-hero-excerpt">
<?php echo the_excerpt(); ?>
</div>
<?php
}
return ob_get_clean();
}
add_shortcode( 'page_hero_excerpt','db_page_hero_excerpt' );
Schortcode: [page_hero_excerpt]
WordPress 5.5 – Disable XML Sitemap
add_action( 'init', function() {\
remove_action( 'init', 'wp_sitemaps_get_server' );\
}, 5 );
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' );
Logout without confirmation
<a class="mw-logout" href="<?php echo wp_logout_url( home_url()); ?>" title="Abmelden">Logout</a>
Hide for logged out users
body:not(.logged-in) .mytest {
display: none!important;
}