WordPress / Gallery Integration Problem Solved

It’s been a few months since I switched from Movable Type to WordPress as a CMS solution.

Overall, I’ve been happy with WordPress. However, there was one large bug I was never able to squash: it didn’t want to play well with Gallery. For some reason, I was never able to call WordPress functions from within the photo gallery pages. I wanted to make these function calls in order to have the side bar menu (which contains recent posts, comments, and other WordPress data) remain consistent on all the pages.

A simple server-side include should have taken care of this, but it never worked. I’d end up with the following error message:

Fatal error: Call to a member function on a non-object in /home/ronrapp/public_html/wp-includes/wp-l10n.php on line 37

The file referenced in the error message, wp-l10n.php, enables WordPress to operate in different languages. Since it’s one of the first things WordPress does, that’s where the functionality broke down.

Normally a Google search will turn up the answer to just about any coding issue, but this one was a rare exception. I posted several messages to the WordPress support forum, but always came away with the feeling that I wasn’t explaining my problem clearly. Either that or the folks replying had no experience with Gallery, which is an admittedly wonky piece of open source software (the next iteration, dubbed “G2”, is supposed to be much better).

Anyway, I’m glad to report that the fog has finally been lifted. The answer: add the following line to the beginning of Gallery’s init.php file:


I’d swear that this is one of the first things I tried four months ago. But apparently not, because it’s working like a charm now. F*%$#ing computers…

  24 comments for “WordPress / Gallery Integration Problem Solved

  1. Jon
    November 17, 2004 at 9:00 am

    I liked Gallery and used it when I was using PHP-Nuke and MT, but switched to something else with WordPress. Man, that G2 has been talked about forever… is it ever going to come out?

  2. Ron
    November 17, 2004 at 11:29 am

    I’m sure G2 will be released eventually. Like WordPress itself, the major updates seem to be fewer and further between as the product matures.

    I can sort of understand why G2 is taking so long. G1 uses the hidden table trick to format the page. Very clunky. It also uses a proprietary data storage system. As I recall, G2 is going to get rid of tables completely and use CSS. It’ll also start storing the data in a SQL database. Those are major structural changes to the way it works. Plus there are so many features in Gallery now that it’s gotta be a pain making this change throughout the software. Watermarking, CMS integration, Oracle support, Java and JS slideshows, IE7, etc.

    I predict G2 will be bitchin when it’s finally released. It’s been in the alpha stage for quite some time and should reach beta fairly soon. There’s still a ton of stuff to do on it. There’s been no security audit on the G2 package yet, and who knows how long that’ll take. They’re still finding holes in G1! In fact I just upgraded to 1.4.4-pl4 to plug one of them…

  3. Geoff
    November 21, 2004 at 8:09 pm

    Could you give a bit more info on how you integrated Gallery and WordPress (e.g., what you were trying to do)? I also just started using WordPress and would love to get the two to reach a nice détente.

    Were you trying to get Gallery to call the WordPress framework? It looks nice.

    Do you have WordPress and Gallery installed in separate directories, or as implied by your example, is Gallery installed inside your WordPress directory? (Hmm, maybe with some RewriteRules, I can fake that.)

    What I’d love to do (and will probably require me coding some sort of WordPress plugin) is to:
    a) easily point to thumbs from Gallery in my WordPress posts. (not so bad, since it’s a lot like the other “abbreviation” plugs.
    b) show the X most recent Gallery thumbs in my WordPress menu. (possible from the Gallery RSS)
    c) random photos from Gallery. (Cool, but I’m dreading that. Maybe if I just stick to a random photo from the RSS.)

  4. Ron
    November 22, 2004 at 12:27 am

    My primary goal was keep the same look and feel throughout the site. So it was just a matter of using the header and footer files in Gallery’s html_wrap subdirectory to call the CSS files used by the WP side of the site.

    I encountered two main problems:

    1) the inability to call WP functions from within Gallery pages, which I wrote about in this post, and

    2) the design would ‘blow out’ when viewing large size individual images. That’s particular to my design since it’s fixed width and sometimes the images are larger than that. If you use a “liquid” design, it’ll make life a little easier when trying to integrate the two.

    I did not get Gallery to call the WP framework per se. I just wanted to get access to the WP functions so I could call specific things for the left side menu bar when on Gallery pages.

    Yes, Gallery is inside the main WP directory. But if you add the require_once line to your init.php file, you should be able to call WP functions from within Gallery no matter where it is located.

    I think you’re right — you’d need to create a plugin to get the functionality you’re looking for. Or at least, that would be the best way of doing it. WP’s plugin system is pretty nice. With as popular as Gallery and WordPress are, I’m surprised someone hasn’t done it already.

    If you’re seriously considering a plugin, you might want to build it for the G2 architecture. It’s going to be considerably different from the current iteration of Gallery.

  5. Pingback: smart brother » Blog Archive » Attempting some slight gallery integration | Don't Push Me, 'cause I'm Close To the Edge
  6. Brian Burns
    December 7, 2004 at 8:54 pm

    Ron – I finally had some free time and tried this – and it worked. If it makes you feel better I could have sworn I had already done this as well…

    Amazing – all that frustration over essentially a single line of code placed appropriately 🙂

    I think I am going to leave my code alone until I tackle Gallery G2 and WordPress 1.3. Probably going to load both current builds up on a test site soon and see how it goes…

    Thanks for the pointer!

  7. December 12, 2004 at 11:45 am


    Wanted to thank you for the updates. I eventually decided for now to just use html_wrap in Gallery to get things to look unified, and haven’t worked up the nerve to have a unified sidebar like you.

    But I did cook up a WP plugin to make it easier to post thumnails/links from Gallery into WP posts. It also includes a PHP function to call from other parts of your WP templates.

    So at the risk of shameless self-promotion… see:

    Feedback welcome and appreciated!

  8. Ron
    December 12, 2004 at 3:08 pm

    Geoff– Great job with the plugin! The only disadvantage to it is something unrelated to your work. It’s more of a fault with Gallery: it’s kinda slow.

    I see more and more people using the Gallery/WP combination, so I have a feeling your plugin will be very popular. I can’t wait to integrate it into my site. As soon as I get back from Las Vegas and have a free moment, I’m going to dive into it.

    Happy holidays! –Ron

  9. December 21, 2004 at 3:32 am

    Hey Ron,

    I’ve been having the exact same error with my gallery integration. I tried what you said, and put in:

    < ?php

    As my gallery directory is in a subdirectory of wordpress. But I got this error:

    Parse error: parse error, unexpected ‘.’ in /www/hosts/silkworms.chinesetriad.org/gallery/init.php on line 25

    Any idea what that is?

  10. Ron
    December 21, 2004 at 10:58 am

    Dave, try using an absolute path (‘../wp-config.php’) with your full path (something like ‘/home/dave/public_html/wp-config.php’) and see if that fixes it.

  11. Mike
    January 11, 2005 at 12:34 pm

    I am having a bitch of a time with this. When I add this I get the “gallery has not been configured” error page. Do you know what would cause that?



  12. Ron
    January 12, 2005 at 12:31 am

    Your Gallery installation works fine until you add this code? Hmmm. Here are a couple of things I can think of:

    – Double check to be sure you’re putting the code in the right place.

    – Also, be sure you changed ‘path/to/wp-config.php’ to your proper path.

    – Another thing that could cause a problem is if there are any blank lines at the top of your init file.

    – You’re not running a G2 alpha are you? This has only been tested with G1.

    You might try inquiring on the support board at wordpress.org. Let me know how it goes.

  13. Mike
    January 12, 2005 at 12:48 am

    Thanks for the reply. I am putting the code right at the top of the init.php file and the syntax looks right. My editor does all that fancy coloring so it does look right. I am using the absolute path for wp-conifg.php and I am not running G2. So basically I just don’t get it. I am starting to get frustrated. I don’t know php for the life of me which makes it all the worse. 🙁


  14. Ron
    January 13, 2005 at 12:16 am

    I’m not sure I can be of much assistance, Mike. I’m sorry about that. But don’t give up. Remember, I encountered the Gallery/Wordpress issue many months ago, and have had to just live with it this whole time! So you’re in good company.

    Someone tipped me off to the solution, otherwise I’d still be up a creek, so to speak.

    Post a message on the WordPress support forum. It can’t hurt. I still receive many URL referrals from those posts, so I know that quite a few WP geeks are reading even those older threads.

  15. Nick
    February 16, 2005 at 2:47 pm

    should this still work with WordPress 1.5 and Gallery 1.4.4?

    I put in the init.php line, and it’s still showing the Gallery skin, not my WordPress theme.

    am I oversimplifying this, and not doing something else to my Gallery that I should be, or is the init.php line intended to basically load the Gallery in the WP theme?

  16. Ron
    February 16, 2005 at 4:13 pm

    Good question. I haven’t touched 1.5 yet, so I have to make the jump from 1.2.2 before figuring out whether or not it’ll work. To be honest, I didn’t even know 1.5 was out until you mentioned it. 🙂

    It appears the new WP theme capability might dictate some changes in how I work the Gallery / WP integration, but I won’t know that until I dig into it.

  17. Bryan Villarin
    February 16, 2005 at 10:57 pm

    Hey Ron, you got Gallery to work with WP 1.5! I’m really trying to find something, especially since I’m not exactly good with all this PHP and CSS stuff. If you get a chance, I hope you can post about how one can do this. Thanks man!

  18. Ron
    February 17, 2005 at 12:26 am

    Bryan, I assume you mean getting WordPress and Gallery to share the same theme? There are some tutorials on the web about how to do this. Try a Google search for WordPress and Gallery integration.

    The thing they don’t address is getting WP functions to work in Gallery. That’s what the code above is designed to address, though I don’t take advantage of it (I actually like it better the way I have it) so I’m not sure if it works in 1.5

    One thing I did find with 1.5 is that due to changes in the functions.php file, the scriptygoddess ‘subscribe to comments’ plugin no longer works.

    If you want any specific info on my installation, let me know. I’d even be happy to send you any config files, style sheets, etc. you might be interested in.

  19. Nick
    February 18, 2005 at 12:56 pm

    well, after a lot of work, I’ve finally got my gallery looking nice in the wordpress theme

    now I can’t log in to my gallery…it pops-up the login window, and takes my password, and then just kicks me back to a not-logged-in gallery

    any tips?

  20. Nick
    February 18, 2005 at 1:20 pm

    heh, figured it out…Gallery is really picky with it’s paths

  21. Allan
    March 16, 2005 at 3:34 am

    Hi Ron, really appreciate your solution.

    I tried sometime ago to call:

    They just never worked.

    Coding the html static layout into “wrapper.footer.default” and “wrapper.header.default” just does seem to be scalable when header and footer change over time.

    The strange thing is that once is in the init.php. WP will print out: “PHP Fatal error: Cannot redeclare _() (previously declared in D:rootdynamicwp-includesfunctions.php:6) in D:rootdynamicgalleryliblang.php on line 179 .”

    if (! gettext_installed()) {
    function _($string) {
    return $string ;

    Listed above line 178 – 181.

    Why didn’t other folks have this problem?
    I haven’t hacked “functions.php” at all. What is the problem then?


  22. Bob
    March 16, 2005 at 8:48 pm


    I’ve been trying to integrate Gallery v1.4.4-pl6 into WordPress v1.5 for a friend’s blog/gallery site I put up for her and have come to a few issues in getting it to work correctly. Basically, in Opera and Firefox, it shows up fine… but in IE it shows up all out of whack: http://gurlrider.mindwiped.com/gallery/ that’s the link… if ya open it in IE, you’ll see the odd alignment issues. I have been racking my brain trying to figure out wtf is wrong.

    I even tried following Dan Cameron’s tutorials over at http://scatteredthoughts.us but those are also for older versions of WordPress. Any ideas on what’s wrong or suggestions to resolve this? Here; I even uploaded the wrapper.header and wrapper.footer info to txt files, as well as the wp-layout.css to a txt file to review the code here: http://www.mindwiped.com/gurlrider/txt/ . Any help, grealt appreciated 🙂


  23. March 27, 2005 at 5:46 pm

    Bob, your problem is that you have double body and head/html tags. You should delete those lines in wrapper.footer and wrapper.header

    Nick, how did you solve the login problem? Picky with what path?

  24. May 8, 2005 at 3:42 am


    The problem is that both Gallery and WordPress set a function called _. To fix the error message, change the code in Gallery to

    if (!gettext_installed()) {
    if (!function_exists(‘_’)) {
    function _($string) {
    return $string;

    The functions do the same things, so it won’t cause a problem.

Leave a Reply


Get the latest posts delivered to your mailbox: