• elfin

    (@elfin)


    On trying out the gallery I notice that for some reason the style associated with this is being added into the content. Surely this should be added to the header with add_action (‘wp_head’,…

    Line 373 of media.php refers.

    Should this be changed? Or am I out on my on with this one?

    [edit: it has already been reported]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter elfin

    (@elfin)

    Just noticed line 412 is missing an end slash as well.
    [edit: it has already been reported]

    It is also a shame that this feature doesn’t appear to work with previously uploaded images either 🙁

    Dickie

    (@dickie)

    It’s worse than that as well… because the CSS is added to the content, it is added for every post that uses it.
    This means that if you have different layout/css for different gallery pages (e.g. 3/4 column layout [gallery columns="3"] etc.) Then when viewing an archive, or an overall blog view when more than one post is on a page at a time, then the last shown post will override the gallery style… Not good.

    Evita

    (@evita)

    Copy the css to your stylesheet and delete it in media.php

    Dickie

    (@dickie)

    Or better still, rather than hack the core code…
    write a plugin to do it…

    Something like this should do the trick, copy all the code and paste into a file called gallerycss.php, make sure you have no white space before or after the php tahs (<? and ?>), upload to your plugins folder and activate. (At your own risk)

    <?php
    /*
    Plugin Name: Move Gallery CSS from body to head
    Plugin URI: http://wordpress.org/support/topic/164825?replies=5#post-722329
    Description: Removes the Gallery CSS declaration and adds into the head
    Author: Dickie
    Version: 1.0
    Author URI:
    */
    
    function test_gallery_removecss($css)
    {
    	// Note you still need to return the start div
    	return '<div class=\'gallery\'>';
    }
    
    function test_gallery_addcss()
    {
    	// Note this is limited to 3 wide column width only
    	echo '<style type=\'text/css\'>
    			.gallery {
    				margin: auto;
    			}
    			.gallery-item {
    				float: left;
    				margin-top: 10px;
    				text-align: center;
    				width: 33%;
    			}
    			.gallery img {
    				border: 2px solid #cfcfcf;
    			}
    			.gallery-caption {
    				margin-left: 0;
    			}
    		</style>';
    }
    add_filter('gallery_style', 'test_gallery_removecss');
    add_action('wp_head','test_gallery_addcss');
    ?>

    Note though that using this you would no longer be able to use the column reference in the gallery shortcode, as that is calculated into the CSS code we have just overridden.
    (e.g. [gallery columns="4"] ), to do that you need to change the %age width in the css in the plugin.

    SpencerLavery

    (@spencerlavery)

    Yeah I noted this just before the official release on the test list, a patch was created but wasn’t implemented in time. I’m sure it will be fixed in the next release.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[gallery]’ is closed to new replies.