Community Documentation

PHP snippets

Last updated October 3, 2011. Created by LeeHunter on November 29, 2005.
Edited by JuliaKM, silverwing, Jody Lynn, sepeck. Log in to edit this page.

This section contains snippets of PHP that you can paste into your Drupal pages, blocks or themes. Often a single PHP block or a single PHP page does exactly what you want, where a module is pure overkill, or just doesn't get you exactly there.

Feel free to add new snippets or enhance existing ones. In fact, please try to reduce duplication as much as possible. It is better to improve an existing page than to add a new one.

For an introduction to snippets, see A beginner's guide to using snippets.

PLEASE NOTE! The following snippets are user-submitted and have not been independently tested. Use at your own risk! Please note that the snippets may contain some database queries specific to MySQL.

EVALUATE a snippet before copying and pasting it into your site. A user could potentially add a snippet that wipes your complete database!

JavaScript snippets should be placed in the JavaScript section.

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x, Drupal 7.x
Audience
Developers and coders

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.