Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm curious as to what the specific differences are between a theme and a plugin. I get the gist of it...themes have to do with look and feel (html / css) and plugins have to do with adding functionality (code / php). However, a theme like the popular twitter inspired P2 seems to add functionality...not simply enhance the look and feel. That leaves me a bit confused. Can someone on this rockin exchange enlighten me?

Much appreciated.

Eddie

share|improve this question
add comment

2 Answers

Imagine in this way! Theme defines MAIN STRUCTURE for whole site! Theme is something like structure for a Post, a Page or a custom post type, custom page,..! So far you know theme is really HTML code! In the end of Wordpress excute, it returns HTML code to browser, and browser display for you! That HTML is build based on theme file (index.php, header.php, footer.php, single.php)

Plugins use hook& filter to modify theme BEFORE we output to browser!

Example: If you want to add social buttons to end of post! You can change single.php and add code to put some social button right below the_content()!

But you can make a plugin to use Wordpress's filter& hook to change HTML of post, to append you social buttons!

You can use hook to add javascript, do some logic code, then render HTML based on that result, then append or replace with something via Wordpress's hook& filter!

But what happen if you put plugin code in theme file? Assume you put some functions to render content into functions.php of theme! Then call those functions manually somewhere on your theme! Or even better, you can use hook& filter to auto change content without manually call in theme!

So as long as wordpress can include your code in someway, and run it! As long as your code run it, it can do anything for you via using hook& filter! Some simple plugins can quite easy to put into a theme file! But some big plugins are too bloat to put into theme file!

Then later, you decide to remove that function, you go to theme file and remove the code? Sound stupid, right? So we have plugin, it's a way to auto modify the running process of Wordpress to change content, to change database,...

Moreover, some hooks are runned before call theme so you can't put theme in theme file!

Conclusions: As long as you code is included by wordpress, wordpress runs it then return result! You can put that code in theme files, wordpress will call it for you! But if you package it as a plugin, you can easy install/deactive/remove without changing any theme files! Additionaly, you also keep your theme simple/clean! So when you need to changing something, put it as a plugin if possible! Don't put it in theme files!

share|improve this answer
add comment

Themes manage the display and layout of your blog, but can also add functionality.

Plug-ins add functionality to your blog, but can also add elements to the layout.

There is a lot of crossover between the two, particularly when you being to bundle certain plug-ins with themes. However, the biggest difference lies in the templates your site uses.

Themes

Themes define the templates used for each page. In general, index.php in a theme is used for just about everything. You can split that out and create a separate header.php and footer.php as well. Then you can add a sidebar.php. I'm sure you've seen at least these four files before - one to define the header, one to define the sidebar, one to define the footer, and one to bring them all together and position them around the main content.

Further, you can define single.php to style a single post, page.php to style individual pages, and so on.

When your site loads and a page or post is requested, WordPress routes the request to the template file defined by your theme. Then it knows how to lay things out on the page. Traditionally, themes are just for layout.

Plug-ins

Plug-ins, on the other hand, can add additional elements to be used by the themes and elsewhere. A plug-in can add a Facebook Like button that your theme can then add to posts and pages. Another plug-in can add a widget to your admin dashboard for accessing and managing your Google Reader feed - this is not reflected in the layout of your site, but does add functionality. Yet another plug-in can automatically post to Twitter whenever you publish a new post.

Themes can add functionality that is directly related to the layout and performance of your site. Plug-ins can add functionality deeper in WordPress - functionality that can also be used by a theme.

share|improve this answer
    
A bit late but what about custom clauses and queries. Would those be part of the theme or a plugin? –  Manny Fleurmond Aug 7 '11 at 0:36
    
Not sure what you mean by custom clauses, but custom queries would/should be handled by plugins. If you're taking an MVC approach, think of WordPress itself as providing the Model (and underlying data access layer), the theme providing the View, and plugins (in addition to certain parts of WordPress) providing the Controller. –  EAMann Aug 7 '11 at 3:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.