body {
background:
/* Update the RGBA value with your own */
linear-gradient(
rgba(255, 0, 0, 0.45),
rgba(255, 0, 0, 0.45)
),
url(URL TO YOUR IMAGE);
}
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;
}
Login / Logout in Navi
add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
function add_login_logout_link($items, $args) {
ob_start();
wp_loginout('index.php');
$loginoutlink = ob_get_contents();
ob_end_clean();
$items .= '<li>'. $loginoutlink .'</li>';
return $items;
}
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]
2023
Lity Lightbox for WordPress
Copy the „Lity“ folder in plugin folder and the name folder „lity“.
Import stylesheet in header
<link href="/wp-content/plugins/lity/dist/lity.css" rel="stylesheet">
Import JS
<script src="/wp-content/plugins/lity/vendor/jquery.js"></script>
<script src="/wp-content/plugins/lity/dist/lity.js"></script>
Download Lity, extract and put it in the „Plugins“ folder
Close Lity Lightbox on browser back button
$(document).on('lity:open', function () {
if (location.hash === '#lity') {
return;
}
history.pushState({}, '', '#lity');
});
$(document).on('lity:close', function () {
if (lity.current()) {
return;
}
history.replaceState({}, '', location.href.split('#')[0]);
});
$(window).on('hashchange', function () {
if (!location.hash && lity.current()) {
lity.current().close();
}
});
Display none – not if Elementor is active
Set element class to:
eledpn
body:not(.elementor-editor-active) .eledpn {
display: none;
}
Color Palette for Gutenberg
add_action( 'after_setup_theme', function() {
add_theme_support( 'editor-color-palette', array(
array(
'name' => __( 'Blue' ),
'slug' => 'blue',
'color' => '#59BACC',
),
array(
'name' => __( 'Green' ),
'slug' => 'green',
'color' => '#58AD69',
),
array(
'name' => __( 'Orange' ),
'slug' => 'orange',
'color' => '#FFBC49',
),
array(
'name' => __( 'Red' ),
'slug' => 'red',
'color' => '#E2574C',
),
) );
} );