wordpress posts template remove default template from menu

Question

Im using wordpress custom post types for “resuorces”
The custom post type is called “resource
Then I created 3 different “post templates” for the post type
webinars, news, gated content
Using different POST TEMPLATES for that.
evertyhing works great there is just one thing I can’t accomplish
need to disable/remove ” Default Template” from the menu
enter image description here
and set “webinar” as the default one..
Couldn’t find a proper answer / function anywhere
Thanks

in progress 0
gil hamer 2 weeks 2021-10-04T04:05:02-05:00 0 Answer 0 views 0

Answer ( 1 )

    0
    2021-10-08T04:03:26-05:00

    If you want to change only the text you can hook into default_page_template_title

    add_filter('default_page_template_title', 'bt_change_default_page_template_title', 10, 2);
    function bt_change_default_page_template_title ($text, $meta) {
        if ($meta === 'meta-box') return 'My custom template';
    
        return $text;
    }
    

    Add this code into functions.php and thats it.
    Tested on a clean wordpress install, this will only change the text and nothing else, functionality will remain the same.

    Update

    To get this filter to work with ACF we need to make a few changes.

    1. ACF doesn’t pass a second argument when using the filter so we need to assing a default value to our second parameter
    2. Update our condition to take that new, empty, parameter into account
    add_filter('default_page_template_title', 'bt_change_default_page_template_title', 10, 2);
    function bt_change_default_page_template_title ($text, $meta = '') {
        if ($meta === 'meta-box' || empty($meta)) return 'My custom templatee';
    
        return $text;
    }
    

Leave an answer

Browse
Browse