We all know how good Wordpress is as blog and decent level CMS system. One of the annoying traits of the gallery script in WordPress is that it embeds a <style> tag in your page overriding all your CSS styles for the gallery. Making it difficult to style the WordPress gallery.

Here is a guide so you can override the default gallery.

  1. Navigate through the root of your website to wp-includes/media.php
  2. Copy the entire function gallery_shortcode($attr){…}
  3. Now navigate over to your current theme folder in /wp-content/themes
  4. Locate the file called functions.php
  5. Paste in the original function and amend the function name to say gallery_shortcode_sk23($attr){…}
  6. Above your newly renamed function add the code:
    remove_shortcode(‘gallery’, ‘gallery_shortcode’);
    add_shortcode(‘gallery’, ‘gallery_shortcode_sk23’);
  7. This will in effect utilise your local function for all gallery short codes.
  8. Now you can amend your version of the gallery shortcode script to your hearts content.
4 Responses to “How to override the default wordpress gallery embedded css styles in WP.”
  1. Calvin Williams

    Thank you so much for this! You have helped me tremendously! I was ready to pull my hair out trying to figure out workarounds until I came across this. Your override fix is genius, thank you again!

  2. Alex

    This is totaly the wrong way, you should never ever alter core files.

    • Martin Toner Web Designer Developer

      I agree, however with this method you aren’t modifying the core files just over-riding the existing function to one you have created yourself in your theme. So you can update the WordPress core files without this function being affected.

  3. Karen Bennett

    Thank you very much for this. It was just the right amount of information, clearly presented. I used it and it worked.