Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    What editor is offering custom size as a drop down option? It’s not the default block editor’s image block. Filters to alter admin meta boxes like that are very unusual, but depending on the editor being used there could be something.

    You could hide the unwanted elements through admin CSS output in a <style> block from the “admin_print_styles” action. A knowledgeable user could get around this and set a custom size anyway, but hiding would stymie nearly all users. I cannot suggest any CSS since I don’t use that editor, but you can use your browser’s element inspector developer tool to help you determine the right CSS. Use the :nth-child() pseudo selector to target specific options in the select drop down.

    • This reply was modified 4 years, 7 months ago by bcworkz.
    Thread Starter pako69

    (@pako69)

    Hi @bcworkz

    It is the default block editor of the WordPress classic editor… : https://i.postimg.cc/Twh374tf/edit-image.jpg

    Moderator bcworkz

    (@bcworkz)

    This added to your theme’s functions.php (preferably of a child theme) ought to hide the option in the image edit modal:

    add_action('admin_print_styles', function() {
        echo '<style>#image-details-size option:last-child {
            display: none;
        }</style>';
    });
    Thread Starter pako69

    (@pako69)

    hi @bcworkz and thanks for the css tips: it works.
    I made it work differently because admin_print_styles is not supposed to be used that way: https://codex.www.ads-software.com/Plugin_API/Action_Reference/admin_print_styles
    Thanks

    Moderator bcworkz

    (@bcworkz)

    You’re welcome. I wasn’t “enqueuing”, I was “printing” ?? All the same, it’s admittedly a little hacky and can possibly not be in the optimal position relative to other style output. IMO it’s OK for short styling needs, but if you have enqueued other admin styles or simply prefer a more proper approach, by all means enqueue an admin stylesheet the proper way.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to remove user custom size?’ is closed to new replies.