Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /home/rachiev4/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340
PHP Archives • Page 2 of 2 • RachieVee: Rachel's Blog Press "Enter" to skip to content

Tag: PHP

10 Ways to Learn WordPress Hooks

WordPress Hooks are hard. We always hear the word “hooks” being thrown around and it’s one of those things that make sense, but then it doesn’t.

I’m sure that there may even people reading this right now, and not entirely sure what I mean by hooks. That’s okay. Before I go on with this post, they look like this. These are two examples I pulled from the Twenty Fifteen Theme in functions.php.

Line 142 of functions.php in Twenty Fifteen.
Line 142 of functions.php in Twenty Fifteen, it’s an action hook.
Line 310 of functions.php in Twenty Fifteen.
Line 310 of functions.php in Twenty Fifteen, it’s a filter hook.

 

Still confused? No worries, it took me a while too. In fact, I can’t say that I completely know all there is to know about WordPress hooks even now, even after writing, “The WordPress Hooks Firing Sequence“. WordPress is the kind of thing that the goal isn’t to learn it all, but to learn it in levels for your purposes. It’s such a deep system, deeper than most people imagine, and I’ve found that once I’ve obtained an understanding of one concept, there is always more to learn. Each concept I learn serves as a foundation for what I learn next.

Hooks didn’t click for me until about a year ago. I too, was copying and pasting various solutions offered by the all knowing Google or Stack Overflow into my WordPress theme. I hadn’t truly understood what was happening when I dropped these snippets of PHP in and the world that would open once that understanding happened.

As much as I’d like to sit here and try to explain what hooks are, if there’s one thing I can say from experience, is that understanding comes in layers. In other words, there is no one mind blowing resource that is suddenly going to make it click. Or maybe it will, depends on the person I guess. For me, however, it took several readings, videos, and diving into WordPress code before the ah hah moment hit.

Knowing that it took a combination of resources and methods for me to learn WordPress hooks, I’d like to pass them onto you. These resources will hopefully bring that fuzzy definition of hooks into focus, even if it’s in layers. In addition to these 10 resources, I’d like to share 2 methods that worked for me. Everyone learns differently and at their own pace, but perhaps sharing my experience will help someone along.

2 Comments

How to Add Counter Classes with a Global Variable


Fatal error: Uncaught Error: Call to a member function id() on array in /home/rachiev4/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php:36 Stack trace: #0 /home/rachiev4/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php(538): CrayonFormatter::format_code('', Array, Object(CrayonHighlighter)) #1 [internal function]: CrayonFormatter::delim_to_internal(Array) #2 /home/rachiev4/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php(516): preg_replace_callback('#()#msi', 'CrayonFormatter...', '/** \r\n* GLOBAL ...') #3 /home/rachiev4/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_highlighter.class.php(166): CrayonFormatter::format_mixed_code('/** \r\n* GLOBAL ...', Object(CrayonLang), Object(CrayonHighlighter)) #4 /home/rachiev4/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_highlighter.class.php(186): CrayonHighlighter->process() #5 /home/rachiev4/public_html/wp-content/plugins/crayon-syntax-high in /home/rachiev4/public_html/wp-content/plugins/crayon-syntax-highlighter/crayon_formatter.class.php on line 36