{"id":5629,"date":"2016-02-16T16:56:01","date_gmt":"2016-02-17T00:56:01","guid":{"rendered":"http:\/\/www.dognmonkey.com\/techs\/?p=5629"},"modified":"2016-02-16T16:56:01","modified_gmt":"2016-02-17T00:56:01","slug":"fotorama-io-in-wordpress-without-plugin","status":"publish","type":"post","link":"https:\/\/www.dognmonkey.com\/mythemes\/fotorama-io-in-wordpress-without-plugin.html","title":{"rendered":"Fotorama.io In WordPress Without Plugin"},"content":{"rendered":"<p>[bs]<\/p>\n<p><em><a href=\"\/\/fotorama.io\/\" target=\"_blank\" rel=\"noopener noreferrer\">Fotorama.io<\/a>\u00a0V4.6.4 is a great Gallery display for\u00a0WordPress. There is a plugin made for WP, but I want to customize for my website and NOT to load all scripts all the time, only when I need to use it. I do prefer this plugin over Galleria.io or lightGallery. I&#8217;ve been using the plugin for WP on many of my posts, so the shortcode for\u00a0<\/em>[ gallery ]\u00a0<em>was used for fotorama plugin, I need to customize my shortcodes to work with both\u00a0<\/em>[ gallery ]<em>and my new shortcodes.<\/em><\/p>\n<p style=\"text-align: center;\">[mybs data=&#8221;1&#8243; title=&#8221;MyFotorama Shortcodes&#8221;]<\/p>\n<blockquote><p>add_shortcode( &#8216;myfotorama&#8217;, &#8216;myfotorama&#8217; );<br \/>\nfunction myfotorama() {<br \/>\nreturn<br \/>\n&#8216;&lt;link href=&#8221;\/idogjs\/fotorama464\/fotorama.css&#8221; rel=&#8221;stylesheet&#8221;&gt;&lt;link href=&#8221;\/idogjs\/fotorama464\/fotorama-wp.css&#8221; rel=&#8221;stylesheet&#8221;&gt;&lt;script src=&#8221;https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.11.2\/jquery.min.js&#8221;&gt;&lt;\/script&gt;&lt;script src=&#8221;\/idogjs\/fotorama464\/fotorama.js&#8221;&gt;&lt;\/script&gt;&lt;script src=&#8221;\/idogjs\/fotorama464\/fotorama-wp.js&#8221;&gt;&lt;\/script&gt;&#8217;<br \/>\n; }<\/p>\n<p style=\"text-align: center;\"><em>This shortcode is for the images with all the options I want<\/em><\/p>\n<p style=\"text-align: left;\">add_shortcode( &#8216;fotorama_body&#8217;, &#8216;my_body&#8217; );<br \/>\nfunction my_body($atts, $content = null) {<br \/>\nextract(shortcode_atts(array(<br \/>\n&#8216;data&#8217; =&gt; &#8221;,<br \/>\n&#8216;title&#8217; =&gt;&#8221;,<br \/>\n), $atts));<br \/>\nreturn<br \/>\n&#8216;&lt;div class=&#8221;fotorama&#8221; data-width=&#8221;600&#8243; data-keyboard=&#8221;true&#8221; data-transition=&#8221;crossfade&#8221; data-allowfullscreen=&#8221;true&#8221; data-nav=&#8221;thumbs&#8221; data-arrows=&#8221;true&#8221; data-click=&#8221;true&#8221; data-swipe=&#8221;true&#8221; data-trackpad=&#8221;true&#8221; data-hash=&#8221;true&#8221;&gt;&#8217;.$content.'&lt;\/div&gt;&#8217;<br \/>\n; }<\/p>\n<\/blockquote>\n<p><em> \u00a0 \u00a0 In order for the [ gallery ] shortcode to work, I need to copy the script from the plugin.<\/em><\/p>\n<blockquote><p>add_shortcode(&#8216;gallery&#8217;, &#8216;fotorama_gallery_shortcode&#8217;);<br \/>\nadd_shortcode(&#8216;fotorama&#8217;, &#8216;fotorama_gallery_shortcode&#8217;);<\/p>\n<p>function fotorama_gallery_shortcode($atts)<br \/>\n{<br \/>\nif (!$atts) {<br \/>\n$atts = array();<br \/>\n}<\/p>\n<p>if (array_key_exists(&#8216;fotorama&#8217;, $atts) &amp;&amp; $atts[&#8216;fotorama&#8217;] == &#8216;false&#8217;) {<br \/>\nreturn gallery_shortcode($atts);<br \/>\n}<\/p>\n<p>$atts[&#8216;link&#8217;] = &#8216;file&#8217;;<br \/>\n$atts[&#8216;itemtag&#8217;] = &#8216;dl&#8217;;<br \/>\n$atts[&#8216;icontag&#8217;] = &#8216;dt&#8217;;<br \/>\n$atts[&#8216;captiontag&#8217;] = &#8216;dd&#8217;;<br \/>\n$atts[&#8216;columns&#8217;] = 0;<\/p>\n<p>if (array_key_exists(&#8216;orderby&#8217;, $atts) &amp;&amp; $atts[&#8216;orderby&#8217;] == &#8216;rand&#8217;) {<br \/>\n$atts[&#8216;orderby&#8217;] = &#8221;;<br \/>\n$atts[&#8216;shuffle&#8217;] = &#8216;true&#8217;;<br \/>\n}<\/p>\n<p>$atts[&#8216;size&#8217;] = &#8216;thumbnail&#8217;;<br \/>\n$gallery = gallery_shortcode($atts);<\/p>\n<p>$width = array_key_exists(&#8216;width&#8217;, $atts) ? $atts[&#8216;width&#8217;] : &#8221;;<br \/>\n$height = array_key_exists(&#8216;height&#8217;, $atts) ? $atts[&#8216;height&#8217;] : &#8221;;<\/p>\n<p>$atts[&#8216;size&#8217;] = &#8216;large&#8217;;<br \/>\npreg_match_all(&#8216;\/(&lt;img[^&lt;&gt;]*&gt;).*\\n*.*&lt;\\\/dt\/&#8217;, gallery_shortcode($atts), $images);<br \/>\npreg_match_all(&#8216;\/href=(\\&#8217;|&#8221;)([^&#8221;\\&#8217;]+)(\\&#8217;|&#8221;).*\\n*.*&lt;\\\/dt\/&#8217;, $gallery, $hrefs);<\/p>\n<p>for ($i = 0, $l = count($images[0]); $i &lt; $l; $i++) {<br \/>\n$image = $images[1][$i];<br \/>\npreg_match(&#8216;\/src=(\\&#8217;|&#8221;)([^&#8221;\\&#8217;]+)(\\&#8217;|&#8221;)\/&#8217;, $image, $src);<\/p>\n<p>if (!$i) {<br \/>\npreg_match(&#8216;\/width=(\\&#8217;|&#8221;)([^&#8221;\\&#8217;]+)(\\&#8217;|&#8221;)\/&#8217;, $image, $__width);<br \/>\n$_width = $__width[2];<\/p>\n<p>preg_match(&#8216;\/height=(\\&#8217;|&#8221;)([^&#8221;\\&#8217;]+)(\\&#8217;|&#8221;)\/&#8217;, $image, $__height);<br \/>\n$_height = $__height[2];<\/p>\n<p>if (!$width) {<br \/>\n$atts[&#8216;width&#8217;] = $_width;<br \/>\n}<\/p>\n<p>if (!$height) {<br \/>\n$height = $_height;<br \/>\n}<br \/>\n}<\/p>\n<p>$quote = $hrefs[1][$i];<br \/>\n$full = $hrefs[2][$i];<\/p>\n<p>$gallery = str_replace($quote . $full . $quote,<br \/>\n$quote . $src[2] . $quote . &#8216; data-full=&#8217; . $quote . $full . $quote,<br \/>\n$gallery);<br \/>\n}<\/p>\n<p>$atts[&#8216;auto&#8217;] = &#8216;false&#8217;;<br \/>\n$atts[&#8216;max-width&#8217;] = &#8216;100%&#8217;;<br \/>\n$atts[&#8216;ratio&#8217;] = array_key_exists(&#8216;ratio&#8217;, $atts) ? $atts[&#8216;ratio&#8217;] : ($_width &amp;&amp; $_height ? $_width \/ $_height : &#8221;);<\/p>\n<p>$data = &#8221;;<br \/>\nforeach ($atts as $key =&gt; $value) {<br \/>\nif ($key != &#8216;fotorama&#8217;) {<br \/>\n$data .= &#8220;data-$key=&#8217;$value'&#8221;;<br \/>\n}<br \/>\n}<\/p>\n<p>return &#8220;&lt;div class=&#8217;fotorama&#8211;wp&#8217; $data&gt;$gallery&lt;\/div&gt;&#8221;;<br \/>\n}<\/p><\/blockquote>\n<p>[\/mybs]<\/p>\n<p style=\"text-align: center;\"><em>[mybs data=&#8221;2&#8243; title=&#8221;Usage&#8221;]<\/em><\/p>\n<p style=\"text-align: left;\"><em>The important thing for these shortcodes to work is not embedded in any &#8220;text&#8221; tags.<\/em><\/p>\n<blockquote>\n<p style=\"text-align: left;\">[ myfotorama ][ fotorama_body ]<\/p>\n<p style=\"text-align: left;\">images.<\/p>\n<p style=\"text-align: left;\">[\/fotorama_body]<\/p>\n<\/blockquote>\n<p style=\"text-align: center;\">[\/mybs]<\/p>\n<p style=\"text-align: center;\"><em>[mybs data=&#8221;3&#8243; title=&#8221;fotorama Gallery Display without Plugin&#8221;]<\/em><\/p>\n<p><link href=\"\/idogjs\/icss\/font-awesome\/css\/ifotorama.css\" rel=\"stylesheet\"><script src=\"https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.11.3\/jquery.min.js\"><\/script><script src=\"\/idogjs\/ijs\/ifotorama.js\"><\/script><div class=\"fotorama\" data-width=\"600\" data-keyboard=\"true\" data-transition=\"crossfade\" data-allowfullscreen=\"true\" data-nav=\"thumbs\" data-arrows=\"true\" data-click=\"true\" data-swipe=\"true\" data-trackpad=\"true\" data-hash=\"true\"><a href=\"https:\/\/www.dognmonkey.com\/mythemes\/wp-content\/uploads\/fotorama_body.jpg\" rel=\"attachment wp-att-5645\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-5645\" src=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/fotorama_body-200x112.jpg\" alt=\"fotorama_body\" width=\"200\" height=\"112\" \/><\/a> <a href=\"https:\/\/www.dognmonkey.com\/mythemes\/wp-content\/uploads\/fotorama_body1.jpg\" rel=\"attachment wp-att-5646\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-5646\" src=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/fotorama_body1-200x112.jpg\" alt=\"fotorama_body1\" width=\"200\" height=\"112\" \/><\/a> <a href=\"https:\/\/www.dognmonkey.com\/mythemes\/wp-content\/uploads\/fotorama_body2.jpg\" rel=\"attachment wp-att-5647\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-5647\" src=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/fotorama_body2-200x112.jpg\" alt=\"fotorama_body2\" width=\"200\" height=\"112\" \/><\/a><\/p>\n[caption id=\"attachment_5519\" align=\"alignnone\" width=\"200\"]<a href=\"https:\/\/www.dognmonkey.com\/mythemes\/wp-content\/uploads\/13disney134-1024x576.jpg\" rel=\"attachment wp-att-5519\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-5519 size-thumbnail\" src=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/2016\/02\/13disney134-1024x576-200x112.jpg\" alt=\"vegas 2013\" width=\"200\" height=\"112\" srcset=\"https:\/\/www.dognmonkey.com\/mythemes\/wp-content\/uploads\/13disney134-1024x576-200x112.jpg 200w, https:\/\/www.dognmonkey.com\/mythemes\/wp-content\/uploads\/13disney134-1024x576-300x169.jpg 300w, https:\/\/www.dognmonkey.com\/mythemes\/wp-content\/uploads\/13disney134-1024x576-768x432.jpg 768w, https:\/\/www.dognmonkey.com\/mythemes\/wp-content\/uploads\/13disney134-1024x576.jpg 1024w\" sizes=\"auto, (max-width: 200px) 100vw, 200px\" \/><\/a> Vegas 2013[\/caption]\n[caption id=\"attachment_5516\" align=\"alignnone\" width=\"200\"]<a href=\"https:\/\/www.dognmonkey.com\/mythemes\/wp-content\/uploads\/13disney106-1024x576.jpg\" rel=\"attachment wp-att-5516\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-5516 size-thumbnail\" src=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/2016\/02\/13disney106-1024x576-200x112.jpg\" alt=\"vegas 1 2013\" width=\"200\" height=\"112\" srcset=\"https:\/\/www.dognmonkey.com\/mythemes\/wp-content\/uploads\/13disney106-1024x576-200x112.jpg 200w, https:\/\/www.dognmonkey.com\/mythemes\/wp-content\/uploads\/13disney106-1024x576-300x169.jpg 300w, https:\/\/www.dognmonkey.com\/mythemes\/wp-content\/uploads\/13disney106-1024x576-768x432.jpg 768w, https:\/\/www.dognmonkey.com\/mythemes\/wp-content\/uploads\/13disney106-1024x576.jpg 1024w\" sizes=\"auto, (max-width: 200px) 100vw, 200px\" \/><\/a> Vegas 2013[\/caption]\n[caption id=\"attachment_5583\" align=\"alignnone\" width=\"200\"]<a href=\"https:\/\/www.dognmonkey.com\/mythemes\/wp-content\/uploads\/z_iphone6_768px.jpg\" rel=\"attachment wp-att-5583\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-5583 size-thumbnail\" src=\"\/\/www.dognmonkey.com\/techs\/wp-content\/uploads\/z_iphone6_768px-200x112.jpg\" alt=\"z_iphone6_768px\" width=\"200\" height=\"112\" srcset=\"https:\/\/www.dognmonkey.com\/mythemes\/wp-content\/uploads\/z_iphone6_768px-200x112.jpg 200w, https:\/\/www.dognmonkey.com\/mythemes\/wp-content\/uploads\/z_iphone6_768px-300x169.jpg 300w, https:\/\/www.dognmonkey.com\/mythemes\/wp-content\/uploads\/z_iphone6_768px.jpg 600w\" sizes=\"auto, (max-width: 200px) 100vw, 200px\" \/><\/a> Galleria 768px display[\/caption]\n<p><\/div>[\/mybs]<\/p>\n<ul class=\"lcp_catlist\" id=\"lcp_instance_0\"><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>[bs] Fotorama.io\u00a0V4.6.4 is a great Gallery display for\u00a0WordPress. There is a plugin made for WP, but I want to customize for my website and NOT to load all scripts all the time, only when I need to use it. I do prefer this plugin over Galleria.io or lightGallery. I&#8217;ve been using the plugin for WP <a href=\"https:\/\/www.dognmonkey.com\/mythemes\/fotorama-io-in-wordpress-without-plugin.html\" class=\"more-link\">&#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[76,54],"tags":[462,473,671],"class_list":["post-5629","post","type-post","status-publish","format-standard","hentry","category-scripts","category-wordpress","tag-fotorama-io","tag-galleria-io","tag-jquery-lightgallery"],"views":15,"_links":{"self":[{"href":"https:\/\/www.dognmonkey.com\/mythemes\/wp-json\/wp\/v2\/posts\/5629","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dognmonkey.com\/mythemes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dognmonkey.com\/mythemes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dognmonkey.com\/mythemes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dognmonkey.com\/mythemes\/wp-json\/wp\/v2\/comments?post=5629"}],"version-history":[{"count":0,"href":"https:\/\/www.dognmonkey.com\/mythemes\/wp-json\/wp\/v2\/posts\/5629\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dognmonkey.com\/mythemes\/wp-json\/wp\/v2\/media?parent=5629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dognmonkey.com\/mythemes\/wp-json\/wp\/v2\/categories?post=5629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dognmonkey.com\/mythemes\/wp-json\/wp\/v2\/tags?post=5629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}