The theme we are using for this site is the GoodInc. theme, a premium template created by WPExplorer. We opted for a premium template after compatibility issues with our last theme with the latest version of WordPress. Our previous theme was heavily modified from the original, and when it broke visually, we opted for a premium theme so that we can get a site back up and running in as quick as time as possible.

One aspect of the GoodInc. theme that we felt was missing, was that the built-in lightbox feature was not automatically applied to single images in a post or page. We have seen other themes, that lacked this feature for their own built-in lightboxes and always wondered why.

The reason the theme authors leave out this functionality, is that there is more bloggers who prefer to use images to contain an external link to other sites and including lightbox functionality on the images would create additional hassles for those bloggers.

Due to different working practices, we never use images for external links, so we sorely missed this functionality. Looking for a solution, we found an edit that can be tweaked for the GoodInc. theme and adds the light box functionality to single images in articles and pages.

Go to Appearances > Editor and select the GoodInc theme. Open up Theme Functions (functions.php) and add the following code to the end of the file;

// Auto insert class

add_filter('the_content', 'my_addlightboxrel');
function my_addlightboxrel($content) {
       global $post;
       $pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
       $replacement = '<a$1href=$2$3.$4$5 class="wpex-lightbox" title="'.$post->post_title.'"$6>';
       $content = preg_replace($pattern, $replacement, $content);
       return $content;

The above code was provided by Tyler Longren, with the class name (wpex-lightbox) added to make the code specific to the GoodInc theme. The code above can be used for any theme with a built-in lightbox function, just change the classname to be specific to the theme you are using.

Applying the built-in Lightbox to Galleries

The following code will allow you to add the built-in lightbox to your image galleries for the GoodInc theme;

When you download the theme, open up the folder JS and edit global.js. Locate line 22;


and change this to;

$('.wpex-gallery-lightbox, .gallery-icon a').magnificPopup({

The above code was supplied by the author of the theme, WPExplorer.

Further Information

Currently we are using the GoodInc theme as is with little modifications. However we enjoy making tweaks to further personalise the site. As we make further changes we will provide our code changes in case it can help other users of the GoodInc theme modify their themes.

  • Black Hat SEO aimed at Shining Waters

    We were recently the subject of a hack attempt where the perpetrators’ main aim appe…
  • Hack Attempt

    Last night around 7:58pm – 8:01pm the site experienced some difficulties as it was u…
Load More Related Articles
Load More By Loch of Shining Waters
Load More In Media & Technology

Leave a Reply

All fields are optional. You do not have to use your real name, pseudonyms are accepted.

Check Also

The importance of local independent news

Written by Chris Matheson MP for City of Chester and Shadow Minister (Digital, Culture, Me…