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?
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 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
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, 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.
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!
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!
Some basic difference between plugin and theme is:
Plugins are found in the wp-content/pluginsdirectory of your WordPress site. Themes can be found in the wp-content/themes directory.
Any WordPress website contain various plugins.But, one Website has only one active theme.
If you are changing theme on your website then you are not able to use features of old theme. While, Installing a new plugin won't affect other active plugins on website.