Skip to content
This repository has been archived by the owner on Apr 2, 2020. It is now read-only.

Allow display of caption HTML even if caption is missing #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

montchr
Copy link
Contributor

@montchr montchr commented Nov 19, 2015

See #61

This is useful for displaying the additional caption HTML for
user-added fields like image credits.

This is useful for displaying the additional caption HTML for
user-added fields like image credits.
@goldenapples
Copy link
Contributor

This makes sense, I guess. I was trying to understand the use case from the issue.

I'm curious what the output of this would be, though. What does img_caption_shortcode do if you have no caption? Are you just hooking a filter on img_caption_shortcode to attach your caption? And if so, could you do the same thing by filtering img_shortcode_output_after_captionify?

@montchr
Copy link
Contributor Author

montchr commented Nov 19, 2015

Are you just hooking a filter on img_caption_shortcode to attach your caption?

Correct. I do this to handle the entire caption <figure> markup with a Twig template:

<figure {{ id }} class="c-img-caption  wp-caption  {{ align }}  {{ classes }}">
    {{ content }}
    {% if caption or credit %}
    <figcaption {{ capid }} class="c-img-caption__text  wp-caption-text">
        {% if caption %}
        <h1 class="c-img-caption__text__caption">{{ caption }}</h1>
        {% endif %}
        {% if credit %}
        <cite class="c-img-caption__text__credit">{{ credit }}</cite>
        {% endif %}
    </figcaption>
    {% endif %}
</figure>

And if so, could you do the same thing by filtering img_shortcode_output_after_captionify?

I think that's too late to do what I'm trying to do, right?

@goldenapples
Copy link
Contributor

I think that's too late to do what I'm trying to do, right?

Not necessarily. If you short-circuit the img_caption_shortcode filter by just returning the image content from it, then apply the filter you originally had in there on img_shortcode_output_after_captionify, I think it would do the same thing as you're presently doing.

I don't think the filters that are in place now are necessarily the best way of organizing the shortcode markup generation, but I haven't come up with a better way yet. Any thoughts?

I don't see the forcecaptionify attribute as something that makes sense for most uses of the shortcode... If you need it in your theme, you might be better off adding it through the img_shortcode_ui_args filter. It might make sense to add a filter in https://github.com/wp-shortcake/image-shortcake/blob/master/inc/class-img-shortcode.php#L228, though, that you could hook into and either check your custom forcecaptionify flag, or just check for the presence of an image credit itself. Would that work for what you're doing?

@montchr
Copy link
Contributor Author

montchr commented Nov 20, 2015

If you short-circuit the img_caption_shortcode filter by just returning the image content from it, then apply the filter you originally had in there on img_shortcode_output_after_captionify, I think it would do the same thing as you're presently doing.

That works great, thanks.

I don't think the filters that are in place now are necessarily the best way of organizing the shortcode markup generation, but I haven't come up with a better way yet. Any thoughts?

I don't have any specific ideas for a better way at the moment — it seems just flexible enough for my use case for now. I do think a general purpose filter for expanding the conditions for displaying the caption would be helpful though.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants