How to use jQuery on DOM in WordPress admin


Having given up on other more proper options, I want to hackily rename the labels of my post formats in the WordPress admin. I’m attempting to directly select the option that has the value “aside” and then rename the label with jQuery.

Here’s as far as I get with my code:


function live_rename_formats() { 

    global $current_screen;

    if ( $current_screen->id == 'post' ) { ?>

        <script type="text/javascript">

            jQuery(document).ready( function( $ ) {

                console.log( $("option[value≈aside]") );

            } );      

    <?php }

add_action('admin_footer', 'live_rename_formats');  

The console log does work, so the script is executing, but it outputs the following object:

a.fn.init [selector: "option[value≈aside]", prevObject: n.fn.init(1), context: document]

When I look inside that object, I see no way to run any function on the “option” DOM element. The outputed object just contains a string saying:

selector: "option[value≈aside]"

I can’t interact with it.

I have also tried hooking it into the admin_head with no luck.

I have never experienced jQuery DOM acting like this, so I presume it has to do with how WordPress handles it, and there I don’t even know where to start.

, Benjamin Antoni Andersen 4 years 2019-11-28T05:53:46-05:00 0 Answers 75 views 0

Leave an answer