Understrap: How to override/unset parent theme templates in Understrap child theme?

Created on 15 Aug 2018  路  4Comments  路  Source: understrap/understrap

Hi, I am trying override/unset parent theme templates in Understrap child theme. Does anyone have a filter or function that works? I don't want users to be able to use 'blank.php' or apply sidebars by changing the 'Template' select menu in Page Attributes in the WP admin.

I have tried numerous blog posts and tutorial - all of which have not worked.

Any help would be appreciated.....

Most helpful comment

Thanks everyone - Code works like a dream.

All 4 comments

Hi, have you tried

add_filter( 'theme_page_templates', 'child_remove_page_templates' );
function child_remove_page_templates( $templates ) {
    unset( $templates['page-templates/right-sidebarpage.php'] );
    unset( $templates['page-templates/left-sidebarpage.php'] );
    unset( $templates['page-templates/both-sidebarspage.php'] );
    unset( $templates['page-templates/blank.php'] );

    return $templates;
}

not tested but docs says it's $page_templates not $templates
https://developer.wordpress.org/reference/hooks/theme_page_templates/#changelog

@0dp is right. While $templates works (for me), you should use

add_filter( 'theme_page_templates', 'child_remove_page_templates' );
function child_remove_page_templates( $page_templates ) {
    unset( $page_templates['page-templates/right-sidebarpage.php'] );
    unset( $page_templates['page-templates/left-sidebarpage.php'] );
    unset( $page_templates['page-templates/both-sidebarspage.php'] );
    unset( $page_templates['page-templates/blank.php'] );

    return $page_templates;
}

which is the docs compliant way to do it.

Thanks everyone - Code works like a dream.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shansmith01 picture shansmith01  路  5Comments

typeplus picture typeplus  路  5Comments

jsgaonac picture jsgaonac  路  5Comments

davidshq picture davidshq  路  3Comments

ibanner picture ibanner  路  5Comments