How to add a link to slide elements in MD Slider? I have used the MD Slider module (which is Mega Slider, a paid module) in my websites to create slideshows.

But there is no default option to create a link for each slide.

Is there any way to hyperlink a slide?
I have created a patch with the changes to convert a slide into hyperlink. Since I cannot upload a file here, I am copy-pasting the contents of my .patch file:

From 3f72f263b3673ce27ca4114963b007752b566c2a Mon Sep 17 00:00:00 2001
From: Raj Pawan Gumdal &lt;gumdal@gmail.com&gt;
Date: Sat, 6 Aug 2016 11:02:04 +0530
Subject: [PATCH 1/2] Ported changes regarding MD_Slider done for an older
 version

---
 .../templates/front/front_layers_render.tpl.php    | 13 ++++----
 .../templates/front/front_slide_render.tpl.php     | 35 ++++++++++++++++++++--
 2 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/sites/all/modules/md_slider/templates/front/front_layers_render.tpl.php b/sites/all/modules/md_slider/templates/front/front_layers_render.tpl.php
index a8dd7fc..16c30b4 100644
--- a/sites/all/modules/md_slider/templates/front/front_layers_render.tpl.php
+++ b/sites/all/modules/md_slider/templates/front/front_layers_render.tpl.php
@@ -11,11 +11,14 @@
 &lt;?php endif;?&gt;
   &lt;div class="&lt;?php print $class; ?&gt;" &lt;?php print $data; ?&gt;&gt;
     &lt;?php if ($layer-&gt;type == 'text'): ?&gt;
-        &lt;?php if (isset($link)):?&gt;
-            &lt;a href="&lt;?php print $link;?&gt;"&lt;?php if (isset($layer-&gt;link["target"]) &amp;&amp; !empty($layer-&gt;link["target"])) print " target='{$layer-&gt;link["target"]}'";?&gt;&gt;&lt;?php print $layer-&gt;title;?&gt;&lt;/a&gt;
-        &lt;?php else:?&gt;
-            &lt;?php print $layer-&gt;title;?&gt;
-        &lt;?php endif; ?&gt;
+    &lt;?php /* Raj: Changes to make MD_Slider slide as hyperlink */?&gt;
+       &lt;?php if (strpos($layer-&gt;title,'URL:') === false):?&gt;
+           &lt;?php if (isset($link)):?&gt;
+               &lt;a href="&lt;?php print $link;?&gt;"&lt;?php if (isset($layer-&gt;link["target"]) &amp;&amp; !empty($layer-&gt;link["target"])) print " target='{$layer-&gt;link["target"]}'";?&gt;&gt;&lt;?php print $layer-&gt;title;?&gt;&lt;/a&gt;
+           &lt;?php else:?&gt;
+               &lt;?php print $layer-&gt;title;?&gt;
+           &lt;?php endif; ?&gt;
+        &lt;?php endif; ?&gt;        
     &lt;?php elseif ($layer-&gt;type == 'image'): ?&gt;
         &lt;?php if (isset($link)):?&gt;
             &lt;a href="&lt;?php print $link;?&gt;"&lt;?php if (isset($layer-&gt;link["target"]) &amp;&amp; !empty($layer-&gt;link["target"])) print " target='{$layer-&gt;link["target"]}'";?&gt;&gt;
diff --git a/sites/all/modules/md_slider/templates/front/front_slide_render.tpl.php b/sites/all/modules/md_slider/templates/front/front_slide_render.tpl.php
index 8df2c39..5dd71dd 100644
--- a/sites/all/modules/md_slider/templates/front/front_slide_render.tpl.php
+++ b/sites/all/modules/md_slider/templates/front/front_slide_render.tpl.php
@@ -18,10 +18,41 @@
       &lt;div class="md-slider-overlay" style="background: &lt;?php print $slide-&gt;settings['background_overlay']; ?&gt;"&gt;
       &lt;/div&gt;
     &lt;?php endif; ?&gt;
-    &lt;div class="md-objects"&gt;
+
+    &lt;?php
+    // Raj: Check if there is a string which starts from "URL:". If so, extract the URL and make this div a hyperlink
+    $hasURL = false;
+    $URLString = '';
+    foreach ($slide-&gt;layers as $index =&gt; $layer):
+    $layerTitle = $layer["title"];
+    drupal_set_message("Layer object: $layer");
+    drupal_set_message("Layer title: $layerTitle");
+    // http://stackoverflow.com/a/4366748/260665
+    if (strpos($layerTitle,'URL:') !== false) {
+       $hasURL = true;
+       $URLString = str_replace('URL:', '', $layerTitle);
+       break;
+    }
+    endforeach;
+    
+    if ($hasURL)
+    {
+       print "&lt;a href=$URLString&gt;";
+    }
+    print "&lt;div class=\"md-objects\"&gt;";
+    foreach ($slide-&gt;layers as $index =&gt; $layer):
+    print theme('front_layers_render', array('index' =&gt; $index, 'layer' =&gt; $layer));
+    endforeach;
+    print "&lt;/div&gt;";
+    if ($hasURL)
+    {
+       print "&lt;/a&gt;";
+    }
+    ?&gt;
+&lt;!--     &lt;div class="md-objects"&gt; --&gt;
       &lt;?php foreach ($slide-&gt;layers as $index =&gt; $layer):?&gt;
         &lt;?php print theme('front_layers_render', array('index' =&gt; $index, 'layer' =&gt; $layer));?&gt;
       &lt;?php endforeach;?&gt;
-    &lt;/div&gt;
+&lt;!--     &lt;/div&gt; --&gt;
   &lt;/div&gt;
 &lt;?php endif;?&gt;
-- 
2.7.4 (Apple Git-66)


From 74c3d0644fd505729163d4803c9a0f9cb014e679 Mon Sep 17 00:00:00 2001
From: Raj Pawan Gumdal &lt;gumdal@gmail.com&gt;
Date: Sat, 6 Aug 2016 14:04:39 +0530
Subject: [PATCH 2/2] Finalized the changes to support hyperlinking whole slide

---
 .../templates/front/front_slide_render.tpl.php     | 30 +++++++++++++---------
 sites/all/themes/IndianSnakes/css/custom.css       |  6 +++++
 2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/sites/all/modules/md_slider/templates/front/front_slide_render.tpl.php b/sites/all/modules/md_slider/templates/front/front_slide_render.tpl.php
index 5dd71dd..764d46e 100644
--- a/sites/all/modules/md_slider/templates/front/front_slide_render.tpl.php
+++ b/sites/all/modules/md_slider/templates/front/front_slide_render.tpl.php
@@ -9,6 +9,7 @@

 &lt;?php if (!isset($slide-&gt;settings["disabled"]) || !$slide-&gt;settings["disabled"]):?&gt;
   &lt;div class="md-slide-item slide-&lt;?php print $index+1;?&gt;" &lt;?php print $data_properties;?&gt;&gt;
+  
     &lt;div class="md-mainimg" style="&lt;?php print $background_style;?&gt;"&gt;
       &lt;?php if (!empty($background_url)):?&gt;
         &lt;img src="&lt;?php print $background_url;?&gt;" alt="&lt;?php print htmlentities($slide-&gt;settings["background_image_alt"], ENT_QUOTES, 'UTF-8');?&gt;"&lt;?php print $background_style;?&gt; /&gt;
@@ -25,34 +26,39 @@
     $URLString = '';
     foreach ($slide-&gt;layers as $index =&gt; $layer):
     $layerTitle = $layer["title"];
-    drupal_set_message("Layer object: $layer");
-    drupal_set_message("Layer title: $layerTitle");
+//     drupal_set_message("Layer object: $layer");
+//     drupal_set_message("Layer title: $layerTitle");
     // http://stackoverflow.com/a/4366748/260665
-    if (strpos($layerTitle,'URL:') !== false) {
+    if (strpos($layerTitle,'URL:') === false) {
+    }
+    else {
        $hasURL = true;
-       $URLString = str_replace('URL:', '', $layerTitle);
+       $URLString = str_replace('URL:','',$layerTitle);
        break;
     }
     endforeach;
-    
+//     drupal_set_message("URL: $URLString");
+//     drupal_set_message("Has URL: $hasURL");
+    $outputString = "";
     if ($hasURL)
     {
-       print "&lt;a href=$URLString&gt;";
+       $outputString .= "&lt;a href=$URLString &gt;"; 
     }
-    print "&lt;div class=\"md-objects\"&gt;";
+    $outputString .= "&lt;div class=\"md-objects\"&gt;";
     foreach ($slide-&gt;layers as $index =&gt; $layer):
-    print theme('front_layers_render', array('index' =&gt; $index, 'layer' =&gt; $layer));
+    $outputString .= theme('front_layers_render', array('index' =&gt; $index, 'layer' =&gt; $layer));
     endforeach;
-    print "&lt;/div&gt;";
+    $outputString .= "&lt;/div&gt;"; 
     if ($hasURL)
     {
-       print "&lt;/a&gt;";
+       $outputString .= "&lt;/a&gt;"; 
     }
+    print $outputString;
     ?&gt;
-&lt;!--     &lt;div class="md-objects"&gt; --&gt;
+&lt;!--     &lt;div class="md-objects"&gt;
       &lt;?php foreach ($slide-&gt;layers as $index =&gt; $layer):?&gt;
         &lt;?php print theme('front_layers_render', array('index' =&gt; $index, 'layer' =&gt; $layer));?&gt;
       &lt;?php endforeach;?&gt;
-&lt;!--     &lt;/div&gt; --&gt;
+&lt;/div&gt; --&gt;
   &lt;/div&gt;
 &lt;?php endif;?&gt;
diff --git a/sites/all/themes/IndianSnakes/css/custom.css b/sites/all/themes/IndianSnakes/css/custom.css
index 3d69b0d..3f0354e 100644
--- a/sites/all/themes/IndianSnakes/css/custom.css
+++ b/sites/all/themes/IndianSnakes/css/custom.css
@@ -27,3 +27,9 @@ display: inline-block;
 width: auto !important;
 height: 300px !important;
 }
+
+/* Reset the hyperlink style to normal inside slides */
+.md-slide-item a {
+    color: inherit;
+    text-decoration: inherit;
+}
\ No newline at end of file
-- 
2.7.4 (Apple Git-66)


I have defined a new "URL:" label protocol for each slide. If a slide has this label defined then the whole slide's div is converted into hyperlink with whatever link is provided after my URL: protocol. For example check this:



The code (patch) is configured such that label with text which begins with URL: is never rendered as text but it is used to convert the slide into a hyperlink.

For a live working example check: http://indiansnakes.org/homepage

Assumption:
The only limitation of this method is, you should not hyperlink any text or images which are used within this hyperlinked slide coz the anchor tags cannot be nested, apparently.

Edit: I thought its best to update the patch details in the MD Slider community as well, here it is: http://megadrupal.com/comment/13066#comment-13066

Also a gist is created with the contents of same patch: https://gist.github.com/gumdal/e580cd80199c871fa52f677538771551