Community Documentation

How to post a snippet so that it actually shows up and doesn't get processed

Last updated October 1, 2011. Created by jerdiggity on June 5, 2009.
Edited by JuliaKM. Log in to edit this page.

There are a lot of users who may not know the "trick" to getting their PHP/HTML code snippets to show up properly; e.g. "How do I post a line of code that normally looks like <a href="this.php">THIS</a> so that it comes out looking like <a href="this.php">THIS</a> instead of being processed and showing up like THIS?"

The answer lies in using the <code> tag to post your PHP and/or HTML code on here (or any Drupal site), in case you didn't know already, which not only is really cool but can also be extremely helpful to whoever's helping you out, whether it's in the forums, if you have a support request, an issue, or whatever the case might be. At the same time, it does you no good if you don't know how to make use of it.

Basically the simple answer is that

anything you post between <code> and </code> will not be treated like actual "code" -- meaning it will not be processed and end up like this -- but rather it will display a formatted version of the letters, numbers, and characters you type in between the opening and closing code tags (which, incidentally, are <code> and </code>, respectively).

Quick example: normally if you were to post something on this site and within that post you typed in this:

<a href="#some-page-that-does-not-exist">click here</a>

... to everyone who reads the post, it would show up on their screen like this:

click here

... as opposed to the code you actually typed in, which, again, would be this:

<a href="#some-page-that-does-not-exist">click here</a>

And actually, by using the code tags, what you would see (or "type" I suppose) would be this:

<code><a href="#some-page-that-does-not-exist">click here</a></code>

... and what everyone else would see would come out looking like this:

<a href="#some-page-that-does-not-exist">click here</a>

The point here is that when you surround the text with the code tags, it tells Drupal, "Leave everything inside here the way it is so other people can see it the same way you see it. In fact (while you're at it), make it look nice too, OK?" :)

Hopefully that gives you at least some clue as to how the whole thing works, in the event that you were unaware or even if you were just "not quite sure."

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 5.x, Drupal 6.x, Drupal 7.x
Audience
Contributors, Designers/themers, Programmers, Site administrators, Site users
Drupal’s online documentation is © 2000-2013 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. Comments on documentation pages are used to improve content and then deleted.
nobody click here