Support » Fixing WordPress » function get_current_screen Can it use by themes/functions.php?

  • If this code is written, an error will occur. WordPress version 3.3 rc2 single

    $screen = get_current_screen();

    Above code create the error log below.

    [11-Dec-2011 09:32:08] PHP Fatal error: Call to undefined function get_current_screen() in /virtual/example/public_html/wp/wp-content/themes/twentyeleven/functions.php on line 596

    WordPress function get_current_screen was exists where wp-admin/includes/screen.php.

    But not included where functions.php

    check code:

    $included_files = get_included_files();

    theme/functions.php 134files included
    not exists wp-admin/includes/screen.php
    wp-admin/index.php 168files included
    exists wp-admin/includes/screen.php
    wp-admin/themes.php 167 files included
    exists wp-admin/includes/screen.php

    Please tell me How do I use this WordPress function?

    Thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • Unless I’m mistaken, get_current_screen is only intended for use when showing an administration screen. Its function is to return the current screen’s hook suffix. If you want to explain what you’re trying to do, I (or someone) might be able to provide a good alternative.

    Hi Big Bagel

    I’m resolved

    My last test code works fine

    Thank you.

    add_action('admin_menu', 'my_theme_menu');
    function my_theme_menu() {
    	$theme_page= add_theme_page('My Theme Options','test','edit_theme_options','myslug','my_Theme_options');
    	if ( $theme_page ){	add_action( 'load-' . $theme_page, 'my_help_tabs_to_theme_page' );}
    function my_theme_options() {
    	echo '<div class="wrap"><p>This is Theme Options page</p></div>';
    function my_help_tabs_to_theme_page() {
    	$screen = get_current_screen();
    	$screen -> add_help_tab(array('id' => 'additional-plugin-help','title' => 'Special Instructions','content' => '<p>This is the content for the tab.</p>'));

    Hi, nobita

    Enter in file functions.php and try to copy this:

    function get_current_screen() {
    global $current_screen;

    if ( ! isset( $current_screen ) )
    return null;

    return $current_screen;


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘function get_current_screen Can it use by themes/functions.php?’ is closed to new replies.