WordPress.org

Forums

Changing gallery code. Is it possible? (4 posts)

  1. richardcz
    Member
    Posted 1 year ago #

    I have made my own theme and I let wordpress generate its gallery. Now, I get something like this:

    <dl class='gallery-item'>
    			<dt class='gallery-icon landscape'>
    				<img width="1200" height="789" src="http://*****.com/wp-content/uploads/2013/08/61-1200x789.jpg" class="attachment-large" alt="6" />
    			</dt></dl>

    My forst question is, can I change this codea that wordpress generates? If so, where? It would be great if I could change it without any plugin. I would like to use the width and add it to styles. It would need to result it into this:

    <dl class='gallery-item'>
    			<dt class='gallery-icon landscape'>
    				<img width="1200" height="789" src="http://*****.com/wp-content/uploads/2013/08/61-1200x789.jpg" class="attachment-large" alt="6" style="max-width:1200px"/>
    			</dt></dl>

    Any suggestions where to change the gallery code?

  2. You want to add style="max-width:1200px" to the <img tag? Have you considered just applying that to the existing CSS tags? That may be easier than using a filter to add that class tag.

    If you can provide a link to a gallery then I could suggest the specific CSS.

  3. alchymyth
    Forum Moderator
    Posted 1 year ago #

    generally, you can code your own gallery code;
    add this to functions.php of your theme:

    remove_shortcode('gallery','gallery_shortcode');
    add_shortcode('gallery','custom_gallery_shortcode');
    
    function custom_gallery_shortcode( $attr ) {
    //your gallery code here//
    }

    for reference, the native gallery shortcode is in /wp-includes/media.php from line 659

  4. gusaroo
    Member
    Posted 1 year ago #

    I'm having a similar issue here;
    http://dev.chalkhillresidency.com/
    user: [ redacted ]
    password: [ redacted ]
    I want the gallery as a whole to align left, but the image area seems to be defaulting to landscape.

    Any help would be much appreciated!
    Lee

Topic Closed

This topic has been closed to new replies.

About this Topic