The function get_current_screen gets the current screen object.
I used a condition inside my callback function to return a script only if the screen id == post:
if( $currentScreen->id === "post" ) {
echo "
<script>
</script>";
}
https://developer.wordpress.org/reference/functions/get_current_screen/
Related Posts:
- How to enqueue scripts on custom post add/edit pages?
- How to use wp.hooks.addAction() in React JS/Gutenberg?
- Extend core block in Gutenberg
- Correct place to register and enqueue scripts
- Hooking a callback into the code within a Gutenberg block
- How to add extra attributes to the script tag added via wp_localize_script()
- What do the args for Gutenberg subpackage “hooks” function “doAction” mean?
- How to wrap the content of the main tinyMCE editor with extra tags
- Use useSelect/useDispatch instead of withSelect/withDispatch
- How to use wp.hooks.addAction() in React JS/Gutenberg?
- How to get value of selected page template in Gutenberg editor?
- Adding nonce or hashes to inline scripts
- Execute JavaScript in WordPress Hook
- ‘wp’ hook supposed to trigger when editing a post?
- What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?
- disable tags on wordpress text editor
- useSelect second parameter
- is_front_page() variable not found
- How do I add some javascript validation to the admin interface form’s onsubmit?
- Get terms of a taxonomy using useSelect
- find out reason of “Updating failed” in Post-editor
- Hook a script as the very last one before the closing body tag
- Cannot read properties of undefined (reading ‘show_ui’) Error on WordPress Post Editor
- Issue migrating a checkbox-type meta field to the block editor
- Client side pre-save Javascript hook on all admin pages
- Call javascript function when add_attachment hook fires
- Move jQuery on *top* of footer
- JavaScript file successfully registered but does not render correctly
- How can I submit a form using JavaScript?
- How do I get the current date in JavaScript?
- How to do a redirect to another route with react-router?
- Jest spy on functionality
- Use a JSON array with objects with javascript
- JavaScript string newline character?
- How to create a GUID / UUID
- How does “/\s/g” replace spaces with other characters?
- What is the correct way to check for string equality in JavaScript?
- JavaScript TypeError: Cannot read property ‘style’ of null
- How to obtain username from Promise
? - How do you check if a variable is an array in JavaScript?
- Static variables in JavaScript
- ReferenceError : window is not defined at object.
Node.js - Node.js Port 3000 already in use but it actually isn’t?
- Uncaught TypeError: $.post is not a function
- Unable to verify leaf signature
- When and why to ‘return false’ in JavaScript?
- In angularjs we are having ng-disabled directive, why ng-enabled directive is not provided by the framework as we are having ng-show and ng-hide
- JavaScript enumerator?
- How to format numbers as currency strings
- Understanding how data-dismiss attribute works in Bootstrap
- Add table row in jQuery
- Node.js document is not defined
- Create table with jQuery – append
- Permutations in JavaScript?
- How do I remove documents using Node.js Mongoose?
- node-request – Getting error “SSL23_GET_SERVER_HELLO:unknown protocol”
- Count the number of occurrences of a character in a string in Javascript
- How to do integer division in javascript (Getting division answer in int not float)?
- javascript unexpected identifier
- How to send email by using javascript or jquery
- Access to Image from origin ‘null’ has been blocked by CORS policy
- Onclick on bootstrap button
- TypeError: res.json is not a function
- JavaScript post request like a form submit
- Jest encountered an unexpected token
- How do I store an array in localStorage?
- How to check if the URL contains a given string?
- How to enable CORS in AngularJs
- bootstrap buttons onclick events
- What are the benefits of using wp_enqueue_script?
- Filter medias from the Media Uploader (wp.media) modal with a post meta
- Create user from outside WordPress through api?
- Add my own function to existing WooCommerce hook
- Load plugin JS in footer
- What’s hook to use immediately after a user is authentcated [duplicate]
- Using wp_localize_script inside template page to transfer var from php to js
- When to use add_action when registering/enqueuing scripts
- How to pass arguments to add_action() or retrieve return value of called function?
- How to get all of the activate_plugin action parameters?
- Setting a menu link to open a pop-up
- Adding buttons to Add New Post and Add New Page
- Media library not working with wp_editor() on the front end
- Save User Meta Email Address in Lowercase
- Is there a media_upload_tabs-similar filter to add tabs to the simple/featured image picker?
- What hook is the currently active theme’s functions.php file loaded on? [duplicate]
- My Button Default Click Is Not Working In WordPress Using Javascript Code
- How can I collect and output all attributes of all executed ShortCodes?
- Gutenberg RangeControl
- Add html code in admin page
- WordPress opens js files as a catalog. Path is right [closed]
- Javascript to open new window
- Javascript File Does Not Work
- Gutenberg sidebar show input field on toggle
- Get the ID of a page in Parent combobox in editor
- Google Page Speed
- Is it feasible to call angular’s page from wordpress website?
- Run only on plug-in activation instead of wp_head
- How do I override the user’s input when updating a custom post type’s permalink?
- How to add a new link to the default register form’s footer links?
- WordPress Gutenberg: Attribute overwritten by block duplicate