A
A
Anatoly2018-08-29 05:29:23
WordPress
Anatoly, 2018-08-29 05:29:23

How to execute code in a specific WordPress admin menu?

How to write a condition in the functions.php file for a certain function, for
example, to execute the code when the user is in the "Categories" section?
if (??????) {
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Yanchevsky, 2018-08-29
@Tolly

The get_current_screen function should help.
I think it's worth trying this:

$screen = get_current_screen();
if($screen->id == 'edit-category') {
    //здесь код
}

Example:
<?php
add_filter('admin_footer', 'screen_test');
function screen_test(){
  $screen = get_current_screen();
  if($screen->id == 'edit-category') {
  ?>
    <script>
      alert('Тест!');
    </script>
  <?php
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question