Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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