0

I'm using the function below to load some javascript that removes the checkbox in the User Profile that is used to toggle the Visual Editor:

//Remove Visual Editor option in User Profile
function remove_visual_editor_admin_script( $hook ){
 if ('user-edit.php' != $hook) {
        return;
    }
    wp_enqueue_script( 'remove_visual_script', get_stylesheet_directory_uri().'/js/remove-visual-editor.js', array('jquery') );
}
add_action('admin_enqueue_scripts','remove_visual_editor_admin_script');

It loads a simple jQuery function in remove-visual-editor.js that removes the HTML and CSS and hides the checkbox.

Problem is, the Visual Editor checkbox appears on two admin pages: one is user-edit.php and the other is profile.php; I'm calling the jQuery script on user-edit.php above.

So I tried an array of page templates, like this

if (array('user-edit.php', 'profile.php') != $hook) {

with no luck.

How to I add the remove-visual-editor.js to both 'user-edit.phpandprofile.php` pages?

Is there another way to add an array or multiple pages to the if line?

2

Use in_array():

if ( in_array( $hook, [ 'user-edit.php', 'profile.php' ] ) )
    // do something

Or wait for the action personal_options, and enqueue the script for the footer. This action is fired in both cases. See this old example.

  • Thanks! Works great. I didn't know that there was no dedicated hook for user management. – markratledge Aug 18 '14 at 3:19
  • Just found out this breaks in the 4.0 Beta. Had to go back to my original function above with no array. – markratledge Aug 25 '14 at 4:49

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.