2

I'm using Wordpress 3.9.1 and I get the

Fatal error: Call to undefined function get_current_screen()

if I put the following in my funcitons.php or in any file of my theme:

$screen = get_current_screen();
echo $screen;

Initially when I got the error, I was working on a theme that I'm creating. However, I tried this with few other themes including TwentyFourteen, and I still got the same error. I even deleted my Wordpress database, created a fresh one and re-installed Wordpress, but still it didn't help.

I checked the get_current_screen() function by going to to wp-admin/includes/screen.php and it is there.

I am working on Xampp and I don't have any plugins activated as it is a fresh install. Also in my wp-config.php I haven't changed anything but the 'MySQL settings' (database, username and password) and 'DEBUG mode'.

Any suggestions on how to rectify this?

  • Please edit more of your code into the question so I can see what you are trying to accomplish. – s_ha_dum May 27 '14 at 13:21
3

get_current_screen() is a backend function and it returns data about the current backend administration page. It makes no sense to use this in theme code. The only way it would work (I think but haven't tested) in functions.php would be if it were hooked into a backend hook later than admin_init.

You don't explain what you are trying to do with get_current_screen() but I think you are simply using it incorrectly.

  • You are right, however I don't know which hook to use. According to the Codex, admin_init will not work. Also, I'm trying to use this to check whether the new/edit page of a custom post type is being viewed, so that I can set different defaults for the custom meta boxes that I've created. I'm using same code to create meta boxes for multiple post types, using a plugin. – user1981248 May 27 '14 at 3:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.