Skip to content

Instantly share code, notes, and snippets.

@EricYue2012
Last active August 6, 2021 01:47
Show Gist options
  • Save EricYue2012/535d0b29abc1e4253406c8f2551ed47a to your computer and use it in GitHub Desktop.
Save EricYue2012/535d0b29abc1e4253406c8f2551ed47a to your computer and use it in GitHub Desktop.
WordPress
<?php
// 1. 显示当前模板文件的路径
// 1. show template file for page
// - put in theme functions.php
function ey_which_template_is_loaded() {
if ( is_super_admin() ) {
global $template;
print_r( $template );
}
}
add_action( 'wp_footer', 'ey_which_template_is_loaded' );
// 2. 给WP dashboard添加CSS style
// add custom style for WP admin
function ey_custom_fonts() {
echo '<style>
.toplevel_page_bridge_core_dashboard {
display: none;
}
</style>';
}
add_action('admin_head', 'ey_custom_fonts');
<?php
// 1. loop导航菜单的链接并修改
add_filter( 'wp_nav_menu_items', 'function_to_update_nav_menu', 10, 2 );
function function_to_update_nav_menu( $items, $args ) {
if (is_user_logged_in()) {
$items .= '<li><a href="'. get_permalink( get_option('woocommerce_myaccount_page_id') ) .'">My Account</a></li>';
//$items = str_replace('My Account', "<img src='https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png'>", $items);
} elseif (!is_user_logged_in() && $args->menu == 303) {
$items .= '<li><a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">Sign in / Register</a></li>';
}
return $items;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment