0

I am trying to change a label on the add new page for a custom post type, but I am having trouble getting any jQuery to operate.

In functions.php, I am enqueueing my script file, after first verifying the page, using the following

wp_enqueue_script('vrscripts', get_stylesheet_directory_uri().'/assets/js/vrscripts.js', array('jquery'), true);

The contents of vrscripts.js is

(function ($) {
// Your code inside here;
    var cur = $('div.edit-post-post-schedule span').text();
    alert(cur);        

})(jQuery);

The alert box displays, but shows only "localhost:5547 says " without showing the contents of the span.

I have also tried

jQuery(document).ready(function ($) {
// Your code inside here;
    var cur = $('div.edit-post-post-schedule span').text();
    alert(cur);        

});

but that yields the same result.

The relevant html section is

<div class="components-panel__row edit-post-post-schedule">
    <span>Publish</span>
    <div class="components-dropdown" tabindex="-1">
        <button type="button" aria-expanded="false" aria-label="Change date: Immediately" class="components-button edit-post-post-schedule__toggle is-tertiary">Immediately</button>
    </div>
</div>

I know I must be missing something simple, but I am at a loss as to what it is. Can anybody point me in the right direction?

Thanks!

2
  • could this not be handled when registering the post type in PHP?
    – Alex Older
    Commented Jun 5, 2023 at 13:46
  • Not so far as I know. I am using PODS and there was a label that I thought would work but did not.
    – Hm Cody
    Commented Jun 5, 2023 at 17:54

1 Answer 1

0

Someone answered, but the answer has since disappeared, which is a shame because it lead me to the solution. What ended up working was

jQuery(document).ready(function ($) {
    setTimeout(function () {
        $('div.edit-post-post-schedule span').text('Birth Date');
        $('div.edit-post-post-schedule span').css('font-weight','bold');
    }, 250);

});

I'm still a bit fuzzy on why it worked, but I will take the win!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.