WordPress.org

Forums

[resolved] Filtering Image Post Format (10 posts)

  1. Stuntbox
    Member
    Posted 2 years ago #

    I use a custom filter in functions.php to remove hard-coded width and height attributes on images. This is a must for implementing responsive designs. But I can't figure out what function to add this filter to remove them from the image post format. Any ideas?

  2. Stuntbox
    Member
    Posted 2 years ago #

    Seriously, does *anyone* know anything about filtering the output of the_post_format_image? Currently it generates a fully-formatted string of HTML, including hard-coded attributes. Same goes for trying to retrieve just an image URL from get_the_post_meta(). Applying filters to the_content have no impact, which is bad since there are custom functions and plugins out there that rely on that to do things like remove width and height attributes for responsive designs, as well as mass-modify img tags for lazy loading. Are we meant to fall back on doing regex's on the output of the_post_format_image to get the various values? Am I missing something obvious here? Would really appreciate any feedback at all on this.

  3. kevinhaig
    Member
    Posted 2 years ago #

    You don't need filters.

    Just set the image width in css to a percentage and height to auto.

  4. Stuntbox
    Member
    Posted 2 years ago #

    Sorry, but there are any number of scenarios where that's a less-than-ideal scenario for handling images in a responsive design. We really, really need the ability to remove these hard-coded width and height img attributes at the theme level.

    I see there are apply_filters for 'content_image' and 'content_images', but I haven't been able to get them to work yet.

  5. This is a must for implementing responsive designs.

    *checks her sites* No it's not. TwentyThirteen defines sizes and yet, as I pull up the site on my phone, the images resize. Ditto Genesis's StudioPress themes.

  6. Stuntbox
    Member
    Posted 2 years ago #

    I apologize if there was some frustration coming through in the tone of my earlier comments. I want to keep this constructive.

    True, while it isn't strictly necessary for implementing flexible images, leaving presentational attributes hard-coded in markup is far from ideal for a lot of RWD scenarios.

    What I'm curious about is a filter hook that lets theme makers handle post format images in a manner similar to what already exists for other images in WordPress, rather than having to write another RegEx-style function to process the fully-formatted HTML string that's returned right now by functions like get_post_format_meta() and the_post_format_image(). This would ease development for those of us working on things like HiDPI image plugins, lazy loading techniques, picture element polyfills, and the like.

    This hook could exist right now and I'm just missing it.

  7. Stuntbox
    Member
    Posted 2 years ago #

    It seems what I'm looking for was suggested by Alex King in Trac but not followed up on:

    http://core.trac.wordpress.org/ticket/19570#comment:148

    Anyone have any info RE status or any other ideas?

  8. It looks like that would need a new trac ticket.

  9. Stuntbox
    Member
    Posted 2 years ago #

    Cool. Not sure if I did this the right way, but here's a Trac ticket for it:

    http://core.trac.wordpress.org/ticket/24162

  10. Stuntbox
    Member
    Posted 2 years ago #

    Also, it looks like Alex has added a patch to that ticket.

Topic Closed

This topic has been closed to new replies.

About this Topic