Add Shortcodes To Sidebar

Since WordPress is php based, in order to use shortcodes on the sidebar or anywhere on the theme, we have to use echo.

<h2><?php echo do_shortcode(‘ catlist categorypage=yes excerpt=yes excerpt_size =255)]’); ?></h2>

This is the shortcodes for catlist to list related posts in the same category on the sidebar for my single.php that I’m designing right now (the right bracket before ‘catlist’ is missing).

  • Galleria.io, lightGallery and Fotorama in Bootstrap Collapsible
    Embed Galleries inside Bootstrap Collapsible. Galleria.io is responsive across desktop, tablets, smartphones, iPhones, iPads with lightbox option, fullscreen with doubletap. Can display multiple galleries on the same page.     Second gallery    : Next lightGallery-Bootstrap Collapsible lightGallery can only display 1 gallery on the same page. Not very easy to use. : Next Fotorama-Bootstrap Collapsible Fotorama.io this is the best one of the 3, easy to use and truly responsive on all devices.  
  • How To Set WP Super Cache To Remember Admin Editing Bar
    After we install and activate WP Super Cache for Wordpress, if we don’t set it correctly, it won’t remember the admin bar when go back from edit screen to the webpage. This is how I set it so it will remember the admin bar.      
  • How To Embed Shortcodes inside a Shortcode
    I created a shortcode for Bootstrap Collapsible, I placed a shortcode inside it like fotorama plugin and fotorama didn’t work. I Googled the problem and I found the fix on WP website. In order for a shortcode to output another shortcode, you need to use ‘do_shortcode($content)’ instead of just ‘$content’ as a content inside the open and close shortcode . add_shortcode( 'mybs', 'mybs_func' ); function mybs_func($atts, $content = null) { extract(shortcode_atts(array( 'data' => '', 'title' =>'', ), $atts)); return '<button type="button" class="btn btn-info" data-toggle="collapse" data-target="'.'#'.$atts.'</button>'. '<div id="'.$atts.'" class="collapse">'.do_shortcode($content).'</div>' ; } Examples: shortcode “myfotorama” top of page. This is a red button This is fotorama gallery inside the collapsible bootstrap body shortcode “gallery ids=”6476,6475,6473,6474,6471″ allowfullscreen=yes”  
  • Warning: Missing argument 2 for wpdb::prepare() Fixed
    When I used a footer that collects the earliest to the newest year to display from the dated posts, I got the “Warning: Missing argument 2 for wpdb::prepare()” on the bottom of the footer. After Googling the problem, I found the fix for it. It’s not a good way to mask the problem like I did before.       The bad codes:  $post_datetimes = $wpdb->get_row($wpdb->prepare(“SELECT YEAR(min(post_date_gmt)) AS firstyear, YEAR(max(post_date_gmt)) AS lastyear FROM $wpdb->posts WHERE post_date_gmt > 1970”)); The good codes: We need to add the blank second argument to make it complete.”1970″,’ ‘));” $post_datetimes = $wpdb->get_row($wpdb->prepare(“SELECT YEAR(min(post_date_gmt)) AS firstyear, YEAR(max(post_date_gmt)) AS lastyear FROM $wpdb->posts WHERE post_date_gmt > 1970”,’ ‘));
  • jQuery lightGallery
    Sometimes I want to embed a gallery inside a bootstrap collapsible paragraph, but Fotorama doesn’t work inside bootstrap collapsible shortcodes. I stumbled into this great jQuery lightGallery and I manage to get it to work inside the bootstrap collapsible shortcodes. To extensively use this lightGallery, you do need support from the owner. I just use this for simple Gallery display. Since I don’t want to load too many scripts on my website, they tend to slow down the page load, so I create shortcodes to load these lightGallery scripts and use them only when needed. For this demo page – -shortcode for bootstrap collapsible scripts -shortcode for lightGallery scripts <div id=”lightgallery” class=”list-unstyled row”> -Images with thumbnails – I made thumbnails as small as possible. -use data-sub-html=” &lt;p&gt;this is the title.&lt;/p&gt; &lt;p&gt;” after the href= for caption. </div> -close bootstrap collapsible shortcode Create a lightgallery.php for shortcode  <?php add_shortcode( ‘mygallery’, ‘mygalleryscript’ ); function mygalleryscript() { return ‘<link href=”/idogjs/lightGallery/dist/css/lightgallery.css” rel=”stylesheet”><script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script><script src=”/idogjs/lightGallery/dist/js/lightgallery.js”></script><script src=”/idogjs/lightGallery/dist/js/lg-fullscreen.js”></script><script src=”/idogjs/lightGallery/dist/js/lg-thumbnail.js”></script><script src=”/idogjs/lightGallery/dist/js/lg-autoplay.js”></script><script src=”/idogjs/lightGallery/dist/js/lg-zoom.js”></script><script src=”/idogjs/lightGallery/dist/js/lg-hash.js”></script><script src=”/idogjs/lightGallery/dist/js/lg-pager.js”></script><script src=”/idogjs/lightGallery/lib/jquery.mousewheel.min.js”></script><script type=”text/javascript”> var $jG=jQuery.noConflict(); $jG(document).ready(function(){ }); </script> <script src=”/idogjs/lightGallery/dist/js/idogGallery.js”></script>’ ; } Include in theme function.php include ‘lightgallery.php’; Make sure all the scripts are in the correct folder url.

Leave a Reply

Your email address will not be published. Required fields are marked *