Skip to content

Instantly share code, notes, and snippets.

@viniciusbig
Created February 2, 2017 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viniciusbig/810109e8e1b5bf96eee6d6673e54f642 to your computer and use it in GitHub Desktop.
Save viniciusbig/810109e8e1b5bf96eee6d6673e54f642 to your computer and use it in GitHub Desktop.
Common snippets for Wordpress
<?php
/**
* Wordpress General Functions
* =============================================================================
*/
/**
* Remove the version number of WP from source code
* Warning - this info is also available in the readme.html file in your root directory - delete this file!
* =============================================================================
*/
remove_action('wp_head', 'wp_generator');
/**
* Replace the standard WordPress logo with our logo
* This uses get_stylesheet_directory_uri to work with child themes
* =============================================================================
*/
function my_theme_name_custom_login_logo() {
print '<style type="text/css">
h1 a {
background-image:url(' . get_stylesheet_directory_uri() . '/images/login.png) !important;
height: 120px !important;
width: 410px !important;
margin-left: -40px;
}
</style>';
}
add_action('login_head', 'my_theme_name_custom_login_logo');
/**
* Customise the login form
* get_bloginfo('stylesheet_directory') gets the Current Theme style folder
* Including Child Theme
* =============================================================================
*/
function my_theme_name_childtheme_custom_login() {
print '<link rel="stylesheet" type="text/css" href="' . get_bloginfo('stylesheet_directory') . '/css/customlogin.css" />';
}
add_action('login_head', 'my_theme_name_childtheme_custom_login');
/**
* Change the link on Login Header to Site Home Page
* =============================================================================
*/
function my_theme_name_login_logo_url() {
// Site Url
return get_bloginfo('url');
}
add_filter('login_headerurl', 'my_theme_name_login_logo_url');
function my_theme_name_login_logo_url_title() {
// Site Name
return get_bloginfo('name');
}
add_filter('login_headertitle', 'my_theme_name_login_logo_url_title');
/**
* Custom WordPress Footer
* =============================================================================
*/
function my_theme_name_custom_admin_footer () {
print 'Copyright ' . date("Y") . ' © ' . get_bloginfo('name') . '. Desenvolvido por Vinicius Arantes';
}
add_filter('admin_footer_text', 'my_theme_name_custom_admin_footer');
/**
* Custom Howdy on Admin Bar
* =============================================================================
*/
function my_theme_name_custom_howdy( $wp_admin_bar ) {
$my_account = $wp_admin_bar->get_node('my-account');
$newtitle = str_replace('Olá', 'Bem vindo', $my_account->title);
$wp_admin_bar->add_node( array(
'id' => 'my-account',
'title' => $newtitle,
) );
}
add_filter('admin_bar_menu', 'my_theme_name_custom_howdy', 25);
/**
* Custom dashboard logo
* All standard icon option: https://developer.wordpress.org/resource/dashicons/
* TODO: this CSS need to be improved. Use ::before instead of background-image
* =============================================================================
*/
function my_theme_name_custom_dashboard_logo() {
print '<style type="text/css">
#wpadminbar #wp-admin-bar-wp-logo > .ab-item .ab-icon:before {
background-image: url("' . get_stylesheet_directory_uri() . '/images/custom_dashboard_logo.png") !important;
}
</style>';
}
// add_action('admin_head', 'my_theme_name_custom_dashboard_logo');
/**
* Remove wordpress icon from admin bar
* =============================================================================
*/
function my_theme_name_remove_annointed_admin_bar() {
global $wp_admin_bar;
/* Remove their stuff */
$wp_admin_bar->remove_menu('wp-logo');
}
add_action('wp_before_admin_bar_render', 'my_theme_name_remove_annointed_admin_bar', 0);
/**
* Adding header meta tags
* =============================================================================
*/
function my_theme_name_add_meta_tags() {
echo '<meta property="og:title" content="" />';
echo '<meta property="og:description" content="" />';
echo '<meta name="keywords" content="" />';
echo '<meta property="og:type" content="website" />';
echo '<meta property="og:site_name" content="" />';
}
add_action('wp_head', 'my_theme_name_add_meta_tags');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment