WordPress WordPress Theme Development Working with CSS and JS in WordPress Themes Adding CSS to a Theme Via the functions.php File

Samuel Tissot-Jobin
Samuel Tissot-Jobin
7,350 Points

Why not use php namespace capabilities instead of long weird function names

like using:


namespace treehouse\wordpress;

function theme_styles(){}


1 Answer

I think it's very useful to do that, although it would require students to understand namespacing and the syntax of loading a namespaced function. Much like this

add_action('wp_enqueue_style', 'treehouse\\wordpress\\theme_styles');

Although I would prefer to use PHP magic NAMESPACE constant in place of that, so

add_action('wp_enqueue_style', __NAMESPACE__.'\\theme_styles');

This is explained much better by this StackOverflow post: http://wordpress.stackexchange.com/questions/63668/autoloading-namespaces-in-wordpress-plugins-themes-can-it-work

And I'm intrigue in using namespaced classes with hooks all grouped inside the class constructor