Replace ul class in Drupal 7 Menu

When theming Drupal Menus you will often want to remove the default styles associated with certain menu elements.

Add Code to template.php

function YOURTHEME_menu_tree__YOURMENU(&$variables) {
  return '<ul class="ADD NEW CLASSES">' . $variables['tree'] . '</ul>';
}


My Theme:

In my case I'm using Twitter BootStrap and replacing the old 'menu nav' ul classes on the Navigation menu so my code looks like this:

Drupal Alerts - AJAX HTTP request terminated abnormally

When playing with frontend editable fields - which at this point in time is far from polished - I was consistently getting interrupted with AJAX alerts. Rather than have these ruin the end user experience it's easier to just re-direct the error through to the console.log with a little bit of JavaScript.

The error

An AJAX HTTP request terminated abnormally.
Debugging information follows.
Path: /system/ajax
StatusText:
ResponseText:
ReadyState: 4


Drupal 7 File Field Paths

When recently attempting to set the path of a file field in Drupal 7 based on a token I found that there was only options available for that of date; page; user; random; site; and variable. Where was the token options for node? A seemingly straight forward task was all of a sudden proving to be very difficult and i was beginning to lose time quickly.

Enable Responsive Video

This is a pretty simple fix to ensure your embedded video clips are responsive when viewed across different devices.

Step 1.

Include the following CSS in your stylesheet:

/* Responsive Video Fix.--------------------*/

.video-container { height:0; overflow:hidden; padding-bottom:56.25%; padding-top:30px; position:relative; }
.video-container iframe, 
.video-container object, 
.video-container embed { height:100%; left:0; position:absolute; top:0; width:100%; }

Custom jQuery in Drupal 7.x

jQuery in Drupal 7.x is namespaced to avoid conflicts with other Javascript libraries such as Prototype. All your code that expects to use jQuery as $ should be wrapped in an outer context.

If you don't do this you may see errors such as "Uncaught TypeError: Property '$' of object [object DOMWindow] is not a function"

Code Example

(function ($) {
  // All your code here
}(jQuery));

Embed a view using a PHP snippet

Sometimes it's handy to be able to embed a Drupal view directly into a page or block. An example of where this is used is on the Tetris Digital Recruitment explore block to produce dynamic lists of content from views within the website.

* Note that this function does NOT display the title of the view. If you want to do that, you will need to do what this function does manually, by loading the view, getting the preview and then getting $view->get_title().

How to delete comments on Google+

I've been doing lot's of experiments with the Google+ system over the past week and noticed a few people asking how to remove a comment from one of your posts. Here is how you do it:

» 1. Goto your profile tab
» 2. Click - The little grey arrow beside your post - 'The Options Menu'
» 3. Click - Report or Remove Comments
» 4. Click - The grey 'X' icon beside the comment to remove it

How is your traffic from Twitter?

The end of the financial year is fast approaching and it presents a great time to stop and look back on your social media marketing efforts for the first half of the year. When evaluating or measuring the success of these efforts a great place to start is by looking at the website statistics to see just how well you are (or are not) doing.

How is your traffic from Twitter?

What is Twitter saying about you?

Companies need to accept that Twitter users and bloggers, especially the higher profile ones, now have a solid journalistic voice when it comes to brand opinion. Reactions to this media are necessary and needs to be treated just as seriously as traditional mediums.

What is Twitter saying about you

How to use Facebook Connect

So you have built your website… You are fairly happy with it… You have updated all the content and put in some nice images. You’ve even done all the hard work ensuring all the keywords and meta tags are appropriate for search engines and are trying your best to keep the blog up-to-date.

How to use Facebook Connect

Starting your social media strategy

Don’t forget about the importance of your own website when planning your social media strategy. I continue to see so many small business operators trying out social media marketing techniques only to visit their website and find something that must have been developed by ‘a friend who knows how to program the web’ back in the 90s.

Starting your social media strategy