Drupal7 update hook dependencies


You sometimes find that update hooks run in an unwanted order that affects their behaviour or creates errors and makes your site crash. You can override this and specify the order that you want with the following hook in your .install file.

 function new_module_update_dependencies() {
  // Run new_module update after old_module update.
  $dependencies['new_module'][7001] = array(
    'old_module' => 7000,
  );
 
  return $dependencies;
 }

Move up metatag in Drupal 7


/**  
* Implements hook_html_head_alter().  
* moving og:title up in head element list  
*/ 
function mymodule_html_head_alter(&$head_elements) {  
  foreach ($head_elements as $key => $element) { 
    if($key == 'metatag_og:title') { 
      $head_elements[$key]['#weight'] = -999; 
    } 
  } 
}

Drupal Update Hook Dependencies


Sometimes, when developing an update hook, you might want it to run after or before a different module’s update hook. this is the way to do it:

Place the following code into your module’s mymodule.install file.

Where 7001 and 7140 are the hook update number.

/**
 * Implementation of hook_update_dependencies().
*/
function mymodule_update_dependencies() {
  // Make sure that mymodule runs after other_module
  $dependencies['mymodule'][7001] = 
 'other_module' => 7140,
);
  return $dependencies;
}

Add different scripts to the header in Drupal (meta, link..)


Now let’s imagine that you want to use a generic function to add different types of scripts to your header: <meta> <link>? <script>. This is the solution I’ve found.

Important: it took me few hours until I realized.

second parameter of drupal_add_html_head must be a unique string, so I’ve used the path to the script because they are in different files inside a folder structure. but you can use a random generator, or maybe a better solution, but keep in mind that must be unique.

$script = "<meta name="google-site-verification" content="xxxxx" />";
drupal_add_html_head(array('#type' => 'markup', '#markup' => $script), "$script");
$script = "<link rel="apple-touch-icon-precomposed" href="www.example.com" />";
drupal_add_html_head(array('#type' => 'markup', '#markup' => $script), "$script");

Remove unnecessary CSS in Drupal 6 & 7


add the function to the template.php file in your theme folder

 

Drupal 6

function mytheme_preprocess_page(&$vars){
 $css = $vars['css'];
//core modules
 unset($css['all']['module']['modules/node/node.css']);
//contrib
 unset($css['all']['module']['sites/all/modules/contrib/filefield/filefield.css']);
//custom
unset($css['all']['module']['sites/all/modules/custom/mymodule/mymodule.css']);
//theme css
unset($css['all']['theme']['sites/all/themes/mytheme/mytheme.css']);

 $vars['styles'] = drupal_get_css($css);
}

 

Drupal 7

 

function mymodule_css_alter(&$css) {
  $exclude = array(
 //core
   'modules/system/maintenance.css' => FALSE,
//contrib
    'sites/all/modules/contrib/module/module.css' => FALSE,
//custom
    'sites/all/modules/custom/module/module.css' => FALSE,
//theme
    'sites/all/themes/mytheme/mytheme.css' => FALSE,
  );
  $css = array_diff_key($css, $exclude);
}

How To Make A Bootstrap Drupal Sub Theme


And of course you’ll want to style it up a little bit, here you have an easy method to modify and compile the theme’s .less files

http://incident57.com/less/video/tutorial.mov

Source : http://drupal.tutsurf.com/ http://incident57.com/less/

20 best Drupal modules for SEO


Drupal is hands down the best CMS for search engine optimization (SEO). The community has contributed a ton of modules to ensure webmasters are adhering to best practices and are equipped for the future. In fact, the wealth of CMS tools provide users with the ability to control all elements of their campaign.

Due to the impending release of Drupal 8, the following list of modules are mainly for Drupal 7. (Drupal typically only supports two versions, so it’s a safe bet to focus on the middle ground of 7 in the meantime). With the proper combination of modules, Drupal morphs into a flexible platform equipped for the ever-changing world of SEO.

1. SEO Compliance Checker

The SEO Compliance Checker delivers feedback on the compliance of a preset series of user-defined rules. Upon creation or modification of nodes, the module will run a set of checks and display the results in a table, indicating what’s perfect, and what might need a little help. Tested elements include title attributes <a href>, keyword density/usage, andatl <img> attributes.

2. SEO Checklist

A vital download. SEO Checklist ensures you’ve dotted the i’s and crossed the t’s in your quest to be the best. The module doesn’t actually enforce any function, but does provide a comprehensive checklist for on-site SEO, marking off each as you complete it. This can prove to be highly valuable for those who aren’t so familiar with the logistics of SEO.

3. Page Title

The Page Title module provides the administrator with the ability to control individual nodes, setting content in the <title> tag. It’s one of the single most important elements in a successful SEO campaign, and a vital module.

4. Path Redirect

With Path Redirect, administrators may redirect URLs from one path to another path. Using this module is important for maintaining the integrity of your site, and preventing search engine crawls from resulting in error. Additionally, links existing on external sites are preserved, and won’t result in a 404.

5. Global Redirect

Global Redirect fixes duplicate URL bugs that tend to occur with clean URLs and the Pathauto module. Although aliases for URLs may appear different, they are in fact duplicate. With the Global Redirect module, a 301 redirect is created from the old node to the alias.

6. Metatag

The concept of meta tags is still a source of comedy. A great deal of weight used to be put on them, and hysteria ensued. The importance has decreased now, though use of the module can’t hurt for providing structured metadata. In reference to SEO,meta tags include meta description tags and the meta keywords tag that search engines often pick up on.

7. Search 404

To ensure that “Not all who wander are lost” Search 404performs a search on the keywords within a non-existing URL. The module does a fantastic job of keeping visitors on your site using search engine keyword detection and expression-based filtering from the URL. Search 404 is highly recommended to keep bounce rates down and user engagement up.

8. XML Sitemap

XML Sitemap generates a dynamic sitemap built for search engines, adhering to the specification of sitemaps.org. It enables you to configure content types, taxonomy terms and more for intelligent crawls from search engines.

9. Site Verification

The Site Verification module helps with the verification process of your website. Supported methods of verification include adding meta tags or uploading a file. Once initiated, a bi-directional check is initiated, and search engines can then verify that you are the site owner.

10. Google Authorship

This is a standard for obtaining authorship information, and not quite a module. Implementing Google Authorship can provide great ranking signals for authors with high credibility. All you have to do is get the authors on your site to create Google+ profiles, then add a rel=”author” attribute. Details on adding user names in Drupal 7 can be found here.

11. Links Checker

The Link Checker module extracts links from content when saved, providing reports on failed responses. Quality issues such as broken links can be a negative signal to search engines.

12. Taxonomy Title

The Taxonomy Title module enables administrators to update the H1 for taxonomy term pages. Keyword-rich and accurate heading tags [e.g. H1, H2, H3] provide structure that is indicated to have some weight in SEO.

13. HTML Purifier

This module filters HTML to ensure rendered output is standards-compliant, removing all malicious code in the process. Without HTML Purifier, users leave themselves open for XSS attacks, especially with WYSIWYG editors.

14. Menu Attributes

The Menu Attributes module enables the administrator to target specific attributes, including id, name, class and styles. The module comes in handy when setting items to “nofollow”, allowing for an effective linking strategy for your website.

15. Footermap

Search engines reward websites engineered for the best user experience. Footermap generates a site map block in the footer region to improve navigation. Use links sparingly and efficiently – there’s a fine line between complete and spammy.

16. Pathauto

The Pathauto module is a staple of Drupal SEO, enabling keyword-rich paths for URLs. Enabling and utilizing Pathauto is double-value, ensuring search engines and site visitors may gather information on content through URLs.

17. Sub-Pathauto

Automatically creates a new alias for URLs based on, or extending, an existing alias. Sub-pathauto allows for further generation of user-friendly URLS.

18. Content Optimizer

In tandem with Content Analysis, Content Optimizer provides statistics and recommended actions to boost search engine rankings. Level Ten provides a great screencast of the Content Optimizer in action. It’s best considered as an integrated version of Google Analytics.

19. Site map

The Site Map module will give site visitors a complete view of the contents of your website, including blogs, categories, and more. Similar to XML sitemap, but more useful as an index page for the site. Drupal generates RSS feeds automatically.

20. Google Analytics

Once you’ve created an account in Google Analytics, you can go ahead and download the Google Analytics module. From there, you’ll have access to key insights on traffic, page logistics, and more. This is highly recommended for any SEO campaign.

Source: http://www.creativebloq.com/20-best-drupal-modules-seo-6133890

Drupal 7 Filtered Gallery (Better Exposed Filters)


Here we have this amazing and simple tutorial made by LevelUpTuts. I’ve been looking for some explanation of how to build this filtered galleries and here it is.

You can filter your gallery depending on the taxonomy.