Add custom function to a theme with child theme’s functions.php
I am using a theme Indigo and have it working fine, in a child theme configuration. I want to add a custom function. Unlike the child style.css, I have read that you don’t need to import the parent functions.php. However when I add my own function to a blank file, functions.php in the child theme folder, my page doesn’t load correctly and I see text from the child functions.php.
I have seen solutions on here requiring that the parent functions.php has functions that can be rewritten.
What are my options here? I want my customizations, but I don’t want a theme update to bork them.
This is what I’m trying to drop in…
/**
* Disable admin bar on the frontend of your website
* for subscribers.
*/
function themeblvd_disable_admin_bar() {
if( ! current_user_can('edit_posts') )
add_filter('show_admin_bar', '__return_false');
}
add_action( 'after_setup_theme', 'themeblvd_disable_admin_bar' );
/**
* Redirect back to homepage and not allow access to
* WP admin for Subscribers.
*/
function themeblvd_redirect_admin(){
if ( ! current_user_can( 'edit_posts' ) ){
wp_redirect( site_url() );
exit;
}
}
add_action( 'admin_init', 'themeblvd_redirect_admin' );
It’s supposed to disable the WP admin bar for low level logins.
FYI I have tested them in the parent functions.php
Leave an answer