You can use admin_footer
or admin_head
like below. This code only run on admin. You can also use for frontend by using wp_head
or wp_footer
function shapeSpace_print_scripts() {
$block_yt_url="test"; ?>
<script>
jQuery(document).ready(function ($) {
let $yt_url = false;
$(document).on( "click", '#yt_run .acf-button-group', function() {
$(".editor-post-publish-button__button").hide();
$(".acf-block-body div div.acf-block-fields.acf-fields div.acf-field.acf-field-text.acf-field-6260f423f1666").css({'height':'inherit','padding':'16px 20px','overflow':'inherit'});
$(".acf-block-body div div.acf-block-fields.acf-fields div.acf-field.acf-field-text.acf-field-6260f423f1666").val(<?php echo $block_yt_url; ?>);
$('#yt_url .acf-input input').keyup(function(e) {
if(e.keyCode == 13) {
$yt_url = true;
};
if(e.keyCode == 46) {
$yt_url = true;
};
if(e.keyCode == 8) {
$yt_url = true;
};
checkStatus();
});
});
function checkStatus(){
if($yt_url) {
$(".editor-post-publish-button__button").show();
}
}
});
</script>
<?php
}
add_action('admin_footer', 'shapeSpace_print_scripts');
If you want it will only load on specific post type editor screen you can add condition like below, I added it for page edit screen only:
if (isset($_GET['post'])) {
$post_id = $_GET['post'];
$post_type = get_post_type($post_id);
if ($post_type !== 'page') {
return;
}
}
This above code is just for idea how you can specifically execute your JS on post type editor.