Hooks and filters are powerful PHP tools in WordPress that allow you to:
- Modify theme behavior without editing core files.
- Add custom features and functionalities to your site.
To add your first custom PHP snippet using hooks or filters, follow the steps below.
Step 1: Install the Child Theme
- Navigate to Theme Options → System.
- Click Install Child Theme if it's not already installed.
Note: A child theme is a minimal, standalone theme that inherits the design and functionality of the parent theme. It allows you to safely add custom PHP or CSS code without affecting the original (parent) theme. During theme updates, only the parent theme will be updated — your child theme and its custom code will remain intact and untouched.
Step 2: Edit the Functions File
- Go to Appearance → Theme File Editor.
- Select functions.php under the Child Theme section.
- Add your PHP snippet at the end of the file.
1. Hooks
1.1 - before_body_content
add_action('uicore_before_body_content', 'uicore_child_before_body_content_hook');
function uicore_child_before_body_content_hook() {
echo 'my super content';
}
1.2 - uicore_before_page_content
add_action('uicore_before_page_content', 'uicore_child__before_page_content__hook');
function uicore_child__before_page_content__hook() {
echo 'my super content';
}
1.3 - uicore_page
add_action('uicore_page', 'uicore_child__page__hook');
function uicore_child__page__hook() {
echo 'my super content';
}
1.4 - uicore_before_content
add_action('uicore_before_content', 'uicore_child__before_content__hook');
function uicore_child__before_content__hook() {
echo 'my super content';
}
1.5 - uicore_content_end
add_action('uicore_content_end', 'uicore_child__content_end__hook');
function uicore_child__content_end__hook() {
echo 'my super content';
}
1.6 - uicore_body_end
add_action('uicore_body_end', 'uicore_child__body_end__hook');
function uicore_child__body_end__hook() {
echo 'my super content';
}
1.7 - uicore_after_portfolio_single
add_action('uicore_after_portfolio_single', 'uicore_child__after_portfolio_single__hook');
function uicore_child__after_portfolio_single__hook() {
echo 'my super content';
}
2. Filters
2.1 - uicore_logo_link
add_filter( 'uicore_logo_link', function(){
return 'https://my-new-url';
});
2.2 - uicore-menu-cache (default value is true)
add_filter('uicore-menu-cache','__return_false');
2.3 - uicore-footer-cache (default value is true)
add_filter('uicore-footer-cache','__return_false');
2.4 - uicore-logo (default logo)
add_filter( 'uicore-logo', function(){
return 'Site Title';
});
2.5 - uicore-mobile-menu-logo (logo displayed on mobile menu)
add_filter( 'uicore-mobile-menu-logo', function(){
return 'Site Title';
});
2.6 - uicore-desktop-menu-logo (fullscreen hamburger menu)
add_filter( 'uicore-desktop-menu-logo', function(){
return 'Site Title';
});
2.7 uicore_portfolio_slug
add_filter( 'uicore_portfolio_slug', function(){
return 'work';
});
2.8 uicore_portfolio_category_slug
add_filter( 'uicore_portfolio_slug', function(){
return 'work-category-slug';
});
2.9 uicore-socials-markup
add_filter( 'uicore-socials-markup', function($markup){
//Do something with $makrup return $markup;
});
2.10 uicore_mobile_menu
add_filter( 'uicore_mobile_menu', function($menu){
return 10; //menu id
});
2.11 uicore_cta_class
add_filter( 'uicore_cta_class', function(){
return ' my-css-class';
});
2.12 uicore_cta_attributes
function uicore_cta_cutom_attr($attributes){
return [
'title' => 'Get Started',
'data-test' => 'test',
'onClick' => 'alert("Hello World")',
];
}
add_filter( 'uicore_cta_attributes', 'uicore_cta_cutom_attr' );
2.13 uicore-mobile-menu-content
add_filter( 'uicore-mobile-menu-content', function() {
$elementor_instance = \Elementor\Plugin::instance();
return $elementor_instance->frontend->get_builder_content_for_display( 1275, true );
});
2.14 uicore-default-blog-img-size
add_filter( 'uicore-default-blog-img-size', function(){
return 'large';
});
2.15 uicore-show-home-in-breadcrumb
add_filter('uicore-show-home-in-breadcrumb', '__return_false');
2.16 uicore_portfolio_img_size
add_filter( 'uicore_portfolio_img_size', function(){
return 'large';
});
2.17 uicore_versions_output
add_filter( 'uicore_versions_output', '__return_false' );
2.18 uicore_hide_admin_customizer (default value is false)
add_filter('uicore_hide_admin_customizer','__return_true');
2.19 uicore_hide_quick_support (Ai Support Chat)
add_filter('uicore_hide_quick_support','__return_true');
2.20 Generic uicore_get_option_OPTION filter
add_filter( 'uicore_get_option_OPTION', function($value){
return 'false';
}, 10);
Replace OPTION with the Theme Options settings you need to filter. Here are some examples:
- header_ctalink
- header_ctatext
Example code:
add_filter( 'uicore_get_option_header_ctalink', function($value){
if(is_user_logged_in()){
return 'https://my-domain.com/my-account';
}
return $value;
}, 10);
add_filter( 'uicore_get_option_header_ctatext', function($value){
if(is_user_logged_in()){
return 'My Account';
}
return $value;
}, 10);
2.21 uicore_global_upload_dir - change the upload folder of CSS and JS assets.
add_filter('uicore_global_upload_dir', function($upload_dir){
// Customize the upload directory here if needed (eg find and replace /uploads/ with /assets/)
$upload_dir['baseurl'] = str_replace('/uploads', '/assets', $upload_dir['baseurl']); //used in the frontend
$upload_dir['basedir'] = str_replace('/uploads', '/assets', $upload_dir['basedir']); //used in the backend
return $upload_dir;
});
Please make sure the new folder (ex: assets) already exists on your server inside the wp-content folder. To regenerate the assets on the new folder, go to Theme Options and Save.
2.22 uicore_pagetitle_title - generic page title filter
The example below removes the word "Category" from the portfolio archive page title:
add_filter('uicore_pagetitle_title', function ($title) {
if(is_tax('portfolio_category')) {
return single_term_title(null, false);
}
return $title;
});
2.23 uicore_get_option_header_transparent - enable/disable transparent header
This is the core filter:
add_filter( 'uicore_get_option_header_transparent', function() {
return 'false';
} );
The example below disables the transparent header on blog posts:
add_action( 'wp', function() {
if ( is_single() && get_post_type() === 'post' ) {
add_filter( 'uicore_get_option_header_transparent', function() {
return 'false';
} );
}
} );