drupal 7

Embed Drupal node form anywhere

Simple 1 line of code to embed a Drupal node form anywhere in your site although I would recommend doing it the Drupal way which is creating a custom module for this.

print drupal_render(node_add('NODE_TYPE'));

Where NODE_TYPE is your content type (machine name).

If the code above returns an error that says the function node_add() is undefined, add the following code before it.

Display Drupal menu local task tab according to node content type

By default every node should have the menu tab (MENU LOCAL TASK) of View and Edit.

If your module wants to add its own tab but only restricted to content type of "foo", then use the following code snippet.

XYZ below is your page callback for the new custom tab. Basically it calls another function to validate user's permission but we manipulate it to check the node type (via access callback).

Themer-friendly menu link CSS classes for Drupal theme

What this code does is to give themers an easier way to style individual menu items in Drupal. For example, if you have a menu item title "Company Profile" and you want this link to be red colour, the following code (to be placed inside template.php file of your theme) will provide menu CSS class of <li class="... menu-company-profile">

Display Drupal block anywhere

Ever wanted to show a Drupal block anywhere in your theme? Use the following code snippet, take note that you will need the module of the block and its delta.

// Load the block region based on module and delta key.
$_your_block = _block_get_renderable_array(_block_render_blocks(array(block_load('MODULE', 'DELTA'))));

// Now we display it.
print render($_your_block);

Add CSS classes to body tag based on your Drupal path

Add custom CSS classes to <body> tag of your theme.

/**
* Implements template_preprocess_html().
*/
function YOUR_THEME_preprocess_html(&$vars) {
  $path = 'your-drupal-page';
  if (drupal_match_path($_GET['q'], $path) || drupal_match_path(drupal_get_path_alias($_GET['q']), $path)) {
    $vars['classes_array'][] = 'page-my-css-class';
  }
}

The $path can be more than one path, separated with newline "\n".

Style Drupal node according to Teaser or Full page view

Allows you to theme nodes according to the view mode. This code provides more template suggestion for you to style.
If you have for example content type "computer", you may copy node.tpl.php in your theme to node--computer.tpl.php or more specifically node--computer-teaser.tpl.php or node--computer-page.tpl.php

Pages