Support » Fixing WordPress » How to check if a user is on the page edit screen but not the post edit screen

  • pixelyzed

    (@pixelyzed)


    Hi there,

    I’m looking for a way to enqueue a small CSS file in the WP admin but only when the user is on the page new or edit screens but NOT the post new or edit screens. I’ll use it to hide a few elements that need to still show on a post edit screen so, just using $pagenow == ‘post.php’ will not work as it’s not specific enough. I’ve also tried get_post_type but as my hook is on admin_init I don’t think the post id is available yet unless I’m doing it wrong . I tried get_post_type (get_the_id()) but it returned false (also tried with global $post).

    Is there any way to do this?

    Thanks in advance for any pointers anyone can provide!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter pixelyzed

    (@pixelyzed)

    No one has a idea if this is doable or how? Thanks!

    You can achieve this by using info from the $_GET array. However you do need to accommodate two situations in your IF clause, one for the new screen (creating a fresh post) and one for the edit screen (an already saved post).

    On a new post/page screen you can get the post type via… $_GET[‘post_type’]

    Once that post/page has been saved, you will instead need to use… get_post_type($_GET[‘post’])

    Just wrap your css file enqueue function in side the following…

    if ($_GET[‘post_type’] == ‘page’ || get_post_type($_GET[‘post’]) == ‘page’) {
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to check if a user is on the page edit screen but not the post edit screen’ is closed to new replies.