Im a bit lost on this simple problem so i thought id come and ask the pros. Ive just been told by my client that on their sites gallery, the name and description are on the same line.
so for example if the picture is called ABC, and the description is “123”.
the output is “ABC-123” all on one line.so itd look like:
--------
| Picture |
--------
ABC-123
She wants the name on one line, and the description on another, like so:
--------
| Picture |
--------
ABC
123
problem is that, i dont even know what im looking for as far as how to edit the code to make this simple change.
On the output code id just enter a quick ‘br’ tag or something like that but again, i dont know where to make this change. As a work around, i went ahead on my local server and in the galleries picture caption area, i put “ABC
123 ” and it worked. it put the name and description on 2 lines but there are A LOT of images on that gallery and im sure theres something more cleaner and elegant than this workaround lol.
any ideas on where i can edit the code?? im using the latest build of WP and all although my theme is custom but its basically default and nothing crazy about it.
im just wondering when you add the gallery code, for example , what page or code block is this referencing?
Thanks in advanced
Let’s assume that your theme is NOT rolling its own gallery shortcode, and let’s assume that you’re using the [gallery] shortcode rather than the ‘gallery’ post format here. What you’re looking for is the ‘gallery_shortcode’ function within
wp-includes/media.php
around line 750 (as of 3.3.1). That’s where the HTML output of your gallery items is hard-coded.Of course, we can’t (well, we really shouldn’t) edit or alter any of the WordPress core files, so we have to look at other ways to hook into, filter or otherwise enhance the built-in features with our own to add the ‘title’ and ‘description’ information you want for each attachment. Unfortunately the way the gallery shortcode was coded, there’s no convenient filter that allows you to add to the content of each gallery item (which makes me think that it might be not a bad idea to submit an enhancement request and a patch… hmm…). So what we have to do instead is replace the entire shortcode function wholesale.
That’s not as hard as it sounds, because we can just copy and paste the built-in code into our own plugin, and then add/modify/mutilate whatever we want.
Here’s how you would do that. In order to make use of this code, simply create a file called ‘WPSE45326_Gallery_Replacement.php” inside your
plugins
folder. Then you have to go into your Admin back-end and activate the new plugin. Then, just make sure the images have a Description and a Title.Note: try this on a Vanilla WordPress install, first. If it works there, but not on your client’s site, then it’s because the theme you’re using is rolling its own code. That would make things more complicated.
Well just in case, anyone is looking at this, i solved the problem by manually inserting a
<br/>
tag in the caption area.so for example if the pictures content has this sample text
"ABC-123"
which outputs thisthen in the caption i entered something like this
ABC<br/>123
which outputs thisThis is the simple gallery (with shortcode) in Wp to which i was referring to and was asked for above http://deadsilencethemovie.com/?page_id=29 (after the br tag) but again, this is just a workaround until something more legit drops for Wp.(if it hasnt already). Thanks all.