Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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:

<?php

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