Ok, I am pretty new to wordpress, and I have been reading a lot of the documentation online and testing things out on my own blog. I have just run into a couple of general questions.
At first glance for a newb editing the PHP is a little over-whelming. Different themes have different files. There is a whole list of functions that I need to get used to. I started to fret because I wasn’t sure where to start if I wanted to make simple tweaks to a post, a page etc.
I have been reading a lot of the documentation of how WordPress is structured and how wordpress posts get populated, so I’m starting to understand a little better, but I still have a question.
I have tried installing a few plugins and some cases I noticed that after I switched themes, the plugin didn’t work. In cases like that, do I need to edit the PHP files of the theme to make the plugin work? Or am I missing settings somewhere.
Any assistance or explanation would be greatly appreciated.
A plugin in WP is a concept more related to user friendly packaging of code, rather than mechanics of code itself.
I don’t want to overly confuse you, but in practice plugin can act like a theme and theme can perform functions common to plugins. Just be aware that these things are more about semantics then code.
When dealing with plugins that interact with theme output it’s important to remember that only way they can accomplish that is by using hooks. Theme is strongly expected to make a number of generic function calls (such as
wp_head()
andwp_footer()
) that set up important hooks and use template tags that come with hooks of their own.So the most likely reason that plugin fails with specific theme is that theme is of poor quality or very outdated and doesn’t provide hooks that plugin requires. There is no generic solutions to this – it entirely depends on specifics of concrete theme and plugins how/if they can be fixed to work together if they don’t.
Switching themes can sometimes reset plugin and widget settings – which is one reason why the plugins would stop working when themes are switched. Second reason for a plugin not working is a poorly written theme that is missing wp_head(), or wp_foot() calls.
My recommendation for understanding WordPress better is to create your own dummy theme from scratch. Along the way you’ll gain more understanding in a controlled, linear fashion.
See http://codex.wordpress.org/Theme_Development
There are many documents on the web describing how this is done, but, the one thing you should focus on is the simplest version.
Just those two files can technically make wordpress work in its entirety, if the theme is coded properly [wp_head(), wp_foot() hooks, etc…].
If you start from a very, very simplified theme and start viewing content through it and different aspects of it – archives, categories, etc, you’ll gain actual appreciation for specialized theme files.
A single index.php can get bloated and confusing (many if statements – such as is_home(), is_category(), etc, exception) which is why WP has a method to split off routines into individual files in a very structured and predictable manner.
Print this graph out: http://codex.wordpress.org/images/1/18/Template_Hierarchy.png
WP will basically check whether a specialized theme file exists (home.php, for example). If it does, it’ll include it when needed. Otherwise, it’ll default to a theme’s index.php.
It gets a bit more complex from that point, but, I think that you typically can’t understand the process unless you crawl along its evolutionary steps.