0

I'm trying to figure out how to add a link/button that when clicked will open the set featured image modal and perform the same functions as if you clicked it in the original meta box. I am wanting to remove the original "Featured Image" meta box so I can group some other fields with it in my custom box.

Any help would be appreciated!

0

you can try this to add custom content in the metabox :

add_action("add_meta_boxes", function (string $post_type, \WP_Post $post) {

    // the post type can be tested here


    $GLOBALS["wp_meta_boxes"]["page"]["side"]["low"]["postimagediv"]["callback"] = function ($post) {

        // the original content to select the featured image
        post_thumbnail_meta_box($post);


        ?>

            <p>
                custom content
            </p>

        <?php

    };


}, 10, 2);
  • Thanks! I believe this will allow me to do what I was trying to do. I copied and pasted the code you provided and it seems to do the trick. Is there any documentation you referenced to come up with this solution. I'm very new to wp development and I'm not fully understanding what your code is doing or how it is working. Thanks again! – lblankenship Mar 26 '18 at 11:43
  • Also could you explain the flipped php open and close tags around the <p> element? – lblankenship Mar 26 '18 at 12:09
  • Sorry one last question, when looking into dbx_post_advanced the codex mentions it is deprecated and advises using the 'add_meta_boxes' instead. I tried updating your code with this but am having issues with the content displaying. Do you know if your method will work with this? – lblankenship Mar 26 '18 at 12:37
  • I don't understand what to explain about php tags. for the deprecated action, I have edited my answer to use add_meta_boxes. – mmm Mar 26 '18 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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