A collection of wordpress functions, for modifying the WordPress Admin Dashboard.
PHP function to change the footer in WordPress Admin Dashboard
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
/*--------------------------------------------------------------
CHANGE FOOTER ADMIN
--------------------------------------------------------------*/
function btwp_change_footer_admin () {
echo 'Theme developed by <a href="https://github.com/theandersonn" target="_blank">theandersonn</a>. Powered by <a href="http://www.wordpress.org" target="_blank">WordPress</a>';
}
add_filter('admin_footer_text', 'btwp_change_footer_admin');
?>
<?php /*-------------------------------------------------------------- CHANGE FOOTER ADMIN --------------------------------------------------------------*/ function btwp_change_footer_admin () { echo 'Theme developed by <a href="https://github.com/theandersonn" target="_blank">theandersonn</a>. Powered by <a href="http://www.wordpress.org" target="_blank">WordPress</a>'; } add_filter('admin_footer_text', 'btwp_change_footer_admin'); ?>
<?php 
/*--------------------------------------------------------------
    CHANGE FOOTER ADMIN
--------------------------------------------------------------*/ 
function btwp_change_footer_admin () {
    echo 'Theme developed by <a href="https://github.com/theandersonn" target="_blank">theandersonn</a>. Powered by <a href="http://www.wordpress.org" target="_blank">WordPress</a>';
}

add_filter('admin_footer_text', 'btwp_change_footer_admin');

?>

PHP function to change the username label in WordPress Admin Dashboard
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
/*--------------------------------------------------------------
CHANGE LOGIN LABEL USERNAME
--------------------------------------------------------------*/
add_action( 'login_head', 'login_function' );
function login_function() {
add_filter( 'gettext', 'username_change', 20, 3 );
function username_change( $translated_text, $text, $domain ) {
if ( $text === 'Username or Email Address' ) {
$translated_text = 'OTHER NAME HERE';
}
return $translated_text;
}
}
?>
<?php /*-------------------------------------------------------------- CHANGE LOGIN LABEL USERNAME --------------------------------------------------------------*/ add_action( 'login_head', 'login_function' ); function login_function() { add_filter( 'gettext', 'username_change', 20, 3 ); function username_change( $translated_text, $text, $domain ) { if ( $text === 'Username or Email Address' ) { $translated_text = 'OTHER NAME HERE'; } return $translated_text; } } ?>
<?php 

/*--------------------------------------------------------------
    CHANGE LOGIN LABEL USERNAME
--------------------------------------------------------------*/ 
add_action( 'login_head', 'login_function' );

function login_function() {
    add_filter( 'gettext', 'username_change', 20, 3 );
    
    function username_change( $translated_text, $text, $domain ) {
        if ( $text === 'Username or Email Address' ) {
            $translated_text = 'OTHER NAME HERE';
        }
        return $translated_text;
    }
}
?>
PHP function to change the post label in WordPress Admin Dashboard
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
/*--------------------------------------------------------------
CHANGE POST LABEL
--------------------------------------------------------------*/
add_action( 'admin_menu', 'change_post_label' );
add_action( 'init', 'change_post_object' );
function change_post_label() {
global $menu;
global $submenu;
$menu[5][0] = 'Mídias';
$submenu['edit.php'][5][0] = 'Mídias';
$submenu['edit.php'][10][0] = 'Adicionar Mídia';
$submenu['edit.php'][16][0] = 'Tags';
echo '';
}
function change_post_object() {
global $wp_post_types;
$labels = &$wp_post_types['post']->labels;
$labels->name = 'Mídias';
$labels->singular_name = 'Mídia';
$labels->add_new = 'Adicionar Mídia';
$labels->add_new_item = 'Adicionar Mídia';
$labels->edit_item = 'Editar Mídia';
$labels->new_item = 'Mídia';
$labels->view_item = 'Ver Mídia';
$labels->search_items = 'Buscar Mídias';
$labels->not_found = 'Nenhum Mídia encontrado';
$labels->not_found_in_trash = 'Nenhum Mídia encontrado no Lixo';
$labels->all_items = 'Todos Mídias';
$labels->menu_name = 'Mídias';
$labels->name_admin_bar = 'Mídias';
}
<?php /*-------------------------------------------------------------- CHANGE POST LABEL --------------------------------------------------------------*/ add_action( 'admin_menu', 'change_post_label' ); add_action( 'init', 'change_post_object' ); function change_post_label() { global $menu; global $submenu; $menu[5][0] = 'Mídias'; $submenu['edit.php'][5][0] = 'Mídias'; $submenu['edit.php'][10][0] = 'Adicionar Mídia'; $submenu['edit.php'][16][0] = 'Tags'; echo ''; } function change_post_object() { global $wp_post_types; $labels = &$wp_post_types['post']->labels; $labels->name = 'Mídias'; $labels->singular_name = 'Mídia'; $labels->add_new = 'Adicionar Mídia'; $labels->add_new_item = 'Adicionar Mídia'; $labels->edit_item = 'Editar Mídia'; $labels->new_item = 'Mídia'; $labels->view_item = 'Ver Mídia'; $labels->search_items = 'Buscar Mídias'; $labels->not_found = 'Nenhum Mídia encontrado'; $labels->not_found_in_trash = 'Nenhum Mídia encontrado no Lixo'; $labels->all_items = 'Todos Mídias'; $labels->menu_name = 'Mídias'; $labels->name_admin_bar = 'Mídias'; }
<?php 

/*--------------------------------------------------------------
    CHANGE POST LABEL
--------------------------------------------------------------*/ 

add_action( 'admin_menu', 'change_post_label' );
add_action( 'init', 'change_post_object' );

function change_post_label() {
    global $menu;
    global $submenu;
    $menu[5][0] = 'Mídias';
    $submenu['edit.php'][5][0] = 'Mídias';
    $submenu['edit.php'][10][0] = 'Adicionar Mídia';
    $submenu['edit.php'][16][0] = 'Tags';
    echo '';
}

function change_post_object() {
    global $wp_post_types;
    $labels = &$wp_post_types['post']->labels;
    $labels->name = 'Mídias';
    $labels->singular_name = 'Mídia';
    $labels->add_new = 'Adicionar Mídia';
    $labels->add_new_item = 'Adicionar Mídia';
    $labels->edit_item = 'Editar Mídia';
    $labels->new_item = 'Mídia';
    $labels->view_item = 'Ver Mídia';
    $labels->search_items = 'Buscar Mídias';
    $labels->not_found = 'Nenhum Mídia encontrado';
    $labels->not_found_in_trash = 'Nenhum Mídia encontrado no Lixo';
    $labels->all_items = 'Todos Mídias';
    $labels->menu_name = 'Mídias';
    $labels->name_admin_bar = 'Mídias';
} 
PHP function to disable drag metabox in WordPress Admin Dashboard
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
/*--------------------------------------------------------------
DISABLE DRAG METABOX DASHBOARD
--------------------------------------------------------------*/
add_action( 'admin_init', 'btwp_disable_drag_metabox_dashboard' );
function btwp_disable_drag_metabox_dashboard() {
wp_deregister_script( 'postbox' );
}
<?php /*-------------------------------------------------------------- DISABLE DRAG METABOX DASHBOARD --------------------------------------------------------------*/ add_action( 'admin_init', 'btwp_disable_drag_metabox_dashboard' ); function btwp_disable_drag_metabox_dashboard() { wp_deregister_script( 'postbox' ); }
<?php
/*--------------------------------------------------------------
    DISABLE DRAG METABOX DASHBOARD
--------------------------------------------------------------*/
add_action( 'admin_init', 'btwp_disable_drag_metabox_dashboard' );

function btwp_disable_drag_metabox_dashboard() {
    wp_deregister_script( 'postbox' );
}
PHP function to hide a item menu in WordPress Admin Dashboard
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
/*--------------------------------------------------------------
HIDE ITEM MENU DASHBOARD
--------------------------------------------------------------*/
add_action( 'admin_menu', 'btwp_hide_item_menu_dashboard' );
function btwp_hide_item_menu_dashboard(){
if( !(current_user_can('administrator')) ) {
remove_menu_page( 'index.php' ); //Dashboard
remove_menu_page( 'edit.php' ); //Posts
remove_menu_page( 'upload.php' ); //Media
remove_menu_page( 'edit.php?post_type=page' ); //Pages
remove_menu_page( 'edit-comments.php' ); //Comments
remove_menu_page( 'themes.php' ); //Appearance
remove_menu_page( 'plugins.php' ); //Plugins
remove_menu_page( 'users.php' ); //Users
remove_menu_page( 'tools.php' ); //Tools
remove_menu_page( 'options-general.php' ); //Settings
}
}
<?php /*-------------------------------------------------------------- HIDE ITEM MENU DASHBOARD --------------------------------------------------------------*/ add_action( 'admin_menu', 'btwp_hide_item_menu_dashboard' ); function btwp_hide_item_menu_dashboard(){ if( !(current_user_can('administrator')) ) { remove_menu_page( 'index.php' ); //Dashboard remove_menu_page( 'edit.php' ); //Posts remove_menu_page( 'upload.php' ); //Media remove_menu_page( 'edit.php?post_type=page' ); //Pages remove_menu_page( 'edit-comments.php' ); //Comments remove_menu_page( 'themes.php' ); //Appearance remove_menu_page( 'plugins.php' ); //Plugins remove_menu_page( 'users.php' ); //Users remove_menu_page( 'tools.php' ); //Tools remove_menu_page( 'options-general.php' ); //Settings } }
<?php
/*--------------------------------------------------------------
  HIDE ITEM MENU DASHBOARD
--------------------------------------------------------------*/
add_action( 'admin_menu', 'btwp_hide_item_menu_dashboard' );

function btwp_hide_item_menu_dashboard(){
  
  if( !(current_user_can('administrator')) ) {
    remove_menu_page( 'index.php' );                  //Dashboard
    remove_menu_page( 'edit.php' );                   //Posts
    remove_menu_page( 'upload.php' );                 //Media
    remove_menu_page( 'edit.php?post_type=page' );    //Pages
    remove_menu_page( 'edit-comments.php' );          //Comments
    remove_menu_page( 'themes.php' );                 //Appearance
    remove_menu_page( 'plugins.php' );                //Plugins
    remove_menu_page( 'users.php' );                  //Users
    remove_menu_page( 'tools.php' );                  //Tools
    remove_menu_page( 'options-general.php' );        //Settings
  }
  
}
PHP function to insert a custom or personalised widget in WordPress Admin Dashboard
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
/*--------------------------------------------------------------
INSERE WIDGET PERSONALIZADO NO DASHBOARD ADMIN
--------------------------------------------------------------*/
function btwp_insert_custom_dashboard_widgets() {
global $wp_meta_boxes;
wp_add_dashboard_widget('custom_help_widget', 'Contate o desenvolvedor', 'btwp_insert_custom_dashboard_help');
}
function btwp_insert_custom_dashboard_help() {
echo '<p>Bem vindo ao sistema do site nome da empresa! Precisa de Ajuda? Contate o desenvolvedor <a href="mailto:email@email.com.br">aqui</a>. Para aceesar o nosso site, visite: <a href="http://www.nome-site.com.br" target="_blank">Nome do Site</a></p>';
}
add_action('wp_dashboard_setup', 'btwp_insert_custom_dashboard_widgets');
<?php /*-------------------------------------------------------------- INSERE WIDGET PERSONALIZADO NO DASHBOARD ADMIN --------------------------------------------------------------*/ function btwp_insert_custom_dashboard_widgets() { global $wp_meta_boxes; wp_add_dashboard_widget('custom_help_widget', 'Contate o desenvolvedor', 'btwp_insert_custom_dashboard_help'); } function btwp_insert_custom_dashboard_help() { echo '<p>Bem vindo ao sistema do site nome da empresa! Precisa de Ajuda? Contate o desenvolvedor <a href="mailto:email@email.com.br">aqui</a>. Para aceesar o nosso site, visite: <a href="http://www.nome-site.com.br" target="_blank">Nome do Site</a></p>'; } add_action('wp_dashboard_setup', 'btwp_insert_custom_dashboard_widgets');
<?php
/*--------------------------------------------------------------
INSERE WIDGET PERSONALIZADO NO DASHBOARD ADMIN
--------------------------------------------------------------*/
function btwp_insert_custom_dashboard_widgets() {
    global $wp_meta_boxes;
    wp_add_dashboard_widget('custom_help_widget', 'Contate o desenvolvedor', 'btwp_insert_custom_dashboard_help');
}

function btwp_insert_custom_dashboard_help() {
    echo '<p>Bem vindo ao sistema do site nome da empresa! Precisa de Ajuda? Contate o desenvolvedor <a href="mailto:email@email.com.br">aqui</a>. Para aceesar o nosso site, visite: <a href="http://www.nome-site.com.br" target="_blank">Nome do Site</a></p>';
}

add_action('wp_dashboard_setup', 'btwp_insert_custom_dashboard_widgets');
PHP function to insert a menu link in the WordPress Admin Dashboard
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
/*--------------------------------------------------------------
INSERT LINK TO THE WP TOOLBAR
--------------------------------------------------------------*/
function btwp_insert_custom_toolbar_link($wp_admin_bar) {
$args = array(
'id' => 'andersonn',
'title' => 'Fale com Andersonn',
'href' => 'https://github.com/theandersonn',
'meta' => array(
'class' => 'andersonn',
'title' => 'Fale com Andersonn'
)
);
$wp_admin_bar->add_node($args);
}
add_action('admin_bar_menu', 'btwp_insert_custom_toolbar_link', 999);
<?php /*-------------------------------------------------------------- INSERT LINK TO THE WP TOOLBAR --------------------------------------------------------------*/ function btwp_insert_custom_toolbar_link($wp_admin_bar) { $args = array( 'id' => 'andersonn', 'title' => 'Fale com Andersonn', 'href' => 'https://github.com/theandersonn', 'meta' => array( 'class' => 'andersonn', 'title' => 'Fale com Andersonn' ) ); $wp_admin_bar->add_node($args); } add_action('admin_bar_menu', 'btwp_insert_custom_toolbar_link', 999);
<?php
/*--------------------------------------------------------------
    INSERT LINK TO THE WP TOOLBAR
--------------------------------------------------------------*/  
function btwp_insert_custom_toolbar_link($wp_admin_bar) {
    $args = array(
        'id' => 'andersonn',
        'title' => 'Fale com Andersonn', 
        'href' => 'https://github.com/theandersonn', 
        'meta' => array(
            'class' => 'andersonn', 
            'title' => 'Fale com Andersonn'
            )
    );
    $wp_admin_bar->add_node($args);
}
add_action('admin_bar_menu', 'btwp_insert_custom_toolbar_link', 999);

PHP function to insert a custom column in the WordPress User Table
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<?php
/*--------------------------------------------------------------
INSERT USER ID COLUMN
--------------------------------------------------------------*/
// Adding the column
add_filter( 'manage_users_columns', 'btwp_user_id_column' );
function btwp_user_id_column( $columns ) {
$columns['user_id'] = 'ID';
return $columns;
}
// Column content
add_action( 'manage_users_custom_column', 'btwp_user_id_column_content', 10, 3 );
function btwp_user_id_column_content( $value, $column_name, $user_id ) {
if ( 'user_id' == $column_name )
return $user_id;
return $value;
}
// Column style
add_action( 'admin_head-users.php', 'btwp_user_id_column_style' );
function btwp_user_id_column_style() {
echo '<style>.column-user_id{width: 5%}</style>';
}
<?php /*-------------------------------------------------------------- INSERT USER ID COLUMN --------------------------------------------------------------*/ // Adding the column add_filter( 'manage_users_columns', 'btwp_user_id_column' ); function btwp_user_id_column( $columns ) { $columns['user_id'] = 'ID'; return $columns; } // Column content add_action( 'manage_users_custom_column', 'btwp_user_id_column_content', 10, 3 ); function btwp_user_id_column_content( $value, $column_name, $user_id ) { if ( 'user_id' == $column_name ) return $user_id; return $value; } // Column style add_action( 'admin_head-users.php', 'btwp_user_id_column_style' ); function btwp_user_id_column_style() { echo '<style>.column-user_id{width: 5%}</style>'; }
<?php 
/*--------------------------------------------------------------
    INSERT USER ID COLUMN
--------------------------------------------------------------*/ 
// Adding the column
add_filter( 'manage_users_columns', 'btwp_user_id_column' );

function btwp_user_id_column( $columns ) {
    $columns['user_id'] = 'ID';
    return $columns;
}

// Column content
add_action( 'manage_users_custom_column',  'btwp_user_id_column_content', 10, 3 );

function btwp_user_id_column_content( $value, $column_name, $user_id ) {
    if ( 'user_id' == $column_name )
        return $user_id;
    return $value;
}


// Column style
add_action( 'admin_head-users.php',  'btwp_user_id_column_style' );

function btwp_user_id_column_style() {
    echo '<style>.column-user_id{width: 5%}</style>';
}