Why should I use get_template_directory() when include files?

get_template_directory() can be filtered. This can be useful when a plugin wants to interact with your theme, for example when you want to write custom plugins to extend the theme without changing it. For example: add_filter( ‘template_directory’, function( $template_dir, $template, $theme_root ) { if ( some_condition( $theme_root ) ) { return plugin_dir_path( __FILE__ ) . … Read more

Add version # to wp_register_style function

I think the issue here is how to read the documentation. The bold code at the top shows how the function is declared by WordPress, not how to use it. Let’s break it down: wp_register_style( string $handle, string|bool $src, string[] $deps = array(), string|bool|null $ver = false, string $media=”all” ) Every possible variable has it’s … Read more

Execute function only for specific user roles

You can exclude certain roles like this: 1- Create a function to check if the current user role is excluded: function isPasswordValidationSkipped() { // Fill this array with roles that you want to exclude from password validation $excludedRoles = [‘subscriber’]; $user = wp_get_current_user(); foreach ($user->roles as $role) { if(in_array($role, $excludedRoles)) { return true; } } … Read more