Skip to content

hybrid_attr_{$slug} filters overwrite attributes defined using hybrid_attr() #54

Closed
naomicbush opened this Issue Jan 1, 2014 · 6 comments

3 participants

@naomicbush

For example, if I want to add a custom class to a post, I'll use:

<?php hybrid_attr( 'post', '', array( 'class' => 'project' ) ); ?>

but then the 'hybrid_attr_post` filter function simply writes over it.

Why not filter the class or add additional classes to the end of the current class value, instead of overwriting it?

Same for hybrid_attr_body, hybrid_attr_content, hybrid_attr_sidebar, hybrid_attr_menu, hybrid_attr_loop_meta, hybrid_attr_loop_title, hybrid_attr_loop_description, hybrid_attr_entry_title, hybrid_attr_entry_author, hybrid_attr_entry_published, hybrid_attr_entry_content, hyrbid_attr_entry_summary, hybrid_attr_entry_terms, hybrid_attr_comment, hybrid_attr_comment_author, hybrid_attr_comment_published, hybrid_attr_comment_permalink, hybrid_attr_comment_content

@naomicbush naomicbush added a commit to naomicbush/hybrid-core that referenced this issue Jan 1, 2014
@naomicbush naomicbush Append class attributes from hybrid_attr_{} filters instead of overwr…
…iting current class. Fix #54
bec8d73
@saas786
saas786 commented Jan 4, 2014

+1, I just started using attr feature, and yes she is right. So please accept the pull request or write yourself appropriately. :)

Thanks.

@justintadlock
Owner

This is not going to happen. If you don't want the default filters to overwrite these values, you don't have to use the default filters.

What I am thinking of doing is removing the third parameter though. I can't really see myself using this too much over the hook anyway.

@naomicbush

@justintadlock so are you saying to remove the default hybrid_attr_{$slug} filter?

The documentation says the filters are meant to be used "to modify, remove, or add any attributes they want without having to edit every template file in the them" — removing it means we don't get the helpful schema support that you've added.

What's the advantage/reason for overwriting the class attribute instead of appending it here?

@justintadlock
Owner

You can remove it, overwrite it, or not use a particular attribute call at all. That's up to you.

Once 2.0 is ready for release, I'll write a more in-depth tutorial explaining the how and why everything works more clearly.

@saas786
saas786 commented Jan 6, 2014

So you are suggesting, I should utilize the filter instead? hybrid_attr_{$slug}

That would and will be v. helpful (as I just started digging attr feature and I am starting to love it ;)).

@justintadlock
Owner

I decided to remove the third parameter, $attributes, for now. I'll reconsider it in a future release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.