Skip to content

Instantly share code, notes, and snippets.

@texe
texe / functions.php
Created July 31, 2022 16:18
WooCommerce - Custom tab
/**
* Custom tab
*/
add_filter( 'woocommerce_product_tabs', 'ct_custom_tab' );
function ct_custom_tab( $tabs ) {
// Adds the new tab
$tabs['test_tab'] = array(
'title' => __( 'Custom Tab', 'woocommerce' ),
'priority' => 50,
@texe
texe / functions.php
Created July 27, 2022 12:13
WordPress - show different menus for logged in users
// Different menus to logged in users
function md_nav_menu_args( $args = '' ) {
if( is_user_logged_in() ) {
// Menu for logged users
$args['menu'] = 22;
} else {
// Menu for non-logged users
$args['menu'] = 23;
}
@texe
texe / functions.php
Created July 18, 2022 10:47
WordPress - change meta generator value
// Remove meta generator tag
function no_generator() { return '<meta name="generator" content="FrontPage 4.0">'; }
add_filter( 'the_generator', 'no_generator' );
@texe
texe / functions.php
Last active July 18, 2022 10:46
WordPress - Remove meta generator tag
// Remove meta generator tag
function no_generator() { return ''; }
add_filter( 'the_generator', 'no_generator' );
@texe
texe / functions.php
Created July 18, 2022 10:11
WordPress - remove version strings from CSS & JS link hrefs in WordPress
//Remove version strings from CSS and JS link hrefs
function ct_remove_version_strings( $src ) {
global $wp_version;
parse_str(parse_url($src, PHP_URL_QUERY), $query);
if ( !empty($query['ver']) && $query['ver'] === $wp_version ) {
$src = remove_query_arg('ver', $src);
}
return $src;
}
@texe
texe / functions.php
Last active July 13, 2022 07:46
WordPress - Change logo url on WordPress' login page
// Change logo url on WordPress login page
add_filter( 'login_headerurl', 'custom_loginlogo_url' );
function custom_loginlogo_url($url) {
return 'https://madlon.eu';
}
@texe
texe / functions.php
Last active July 8, 2022 06:15
WordPress - Change logo on WordPress' login page
// Change logo on login page
function my_custom_login_logo() {
echo '<style type="text/css">
h1 a { background-image:url(https://your-domain.com/wp-content/uploads/custom-logo.png) !important; }
</style>';
}
add_action('login_head', 'my_custom_login_logo');
@texe
texe / functions.php
Created July 7, 2022 13:37
WooCommerce - Rename tabs
/**
* Rename product data tabs
*/
add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 );
function woo_rename_tabs( $tabs ) {
// Rename the description tab
$tabs['description']['title'] = __( 'More Information' );
// Rename the reviews tab
@texe
texe / functions.php
Last active July 7, 2022 12:21
WordPress - Login/logout link depends on user is logged
// shortcode for Login/register vs Logout
function md_login_logout() {
if ( is_user_logged_in()) {
$link = '<a href="' . wp_logout_url() . '">Logout</a>';
}
if ( !is_user_logged_in()) {
$link = '<a href="/my-account/edit-account/">Login/Register</a>';
}
return $link;
}
@texe
texe / functions.php
Last active August 2, 2023 12:52
WordPress - Redirect to home page after login/logout in WordPress
// redirect to home after login/logout
add_action('wp_logout','go_home');
function go_home(){
wp_redirect( home_url() );
exit();
}
add_action('wp_login','go_home_after_login');
function go_home_after_login(){
wp_redirect( home_url() );