• Resolved whanklee

    (@whanklee)


    Hi,

    I would like to add a JavaScript code to admin page only. I didn’t find any option for it. I am able to add JS code to frontend only.

    For example:

    var oldVal = "";
    $("#textarea").on("change keyup paste", function() {
    var currentVal = $(this).val();
    if(currentVal == oldVal) {
    return; //check to prevent multiple simultaneous triggers
    }
    
    oldVal = currentVal;
    //action to be performed on textarea changed
    alert("changed!");
    
    });

    Could you help me how to add this code to admin page? What and how can I do this?

    • This topic was modified 2 years, 9 months ago by whanklee.
Viewing 1 replies (of 1 total)
  • Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @whanklee,

    There’s no built-in way to add JavaScript in the admin at the moment so you can do that by using some PHP code like this:

    	
    add_action( 'admin_head', function() {
    ?>
    	<script>
    		// Your JS code here.
    	</script>
    	<?php
    } );
    

    You can set this to run in the Admin Only location.

Viewing 1 replies (of 1 total)

The topic ‘How to add JavaScript to admin page’ is closed to new replies.