Community Forums › Forums › Archived Forums › Design Tips and Tricks › Making filters affect custom loop only
Tagged: custom loop, Custom Post Type, schema markup
- This topic has 2 replies, 2 voices, and was last updated 9 years, 6 months ago by Graham.
-
AuthorPosts
-
June 9, 2015 at 12:42 pm #155608GrahamMember
Think I'm missing something obvious here, yet am hoping someone can point me in the right direction ..
I have a CPT ( vlhdir_entry) archive being displayed using a custom loop in archive-vlhdir_entry.php. As the entries are organisations and not blog posts, I filtered the mark up attributes to use the relevant schema mark up . Added using CPT conditional in the plugin file
e.g.
add_action( 'genesis_header', 'vlhdir_edits' ); function vlhdir_edits() { if ( get_post_type() == 'vlhdir_entry' ) { remove_filter( 'genesis_attr_entry', 'genesis_attributes_entry' ); add_filter( 'genesis_attr_entry', 'vlhdir_attributes_entry' ); // etc } } function vlhdir_attributes_entry( $attributes ) { $attributes['class'] = join( ' ', get_post_class() ); $attributes['itemscope'] = 'itemscope'; $attributes['itemtype'] = 'http://schema.org/Organization'; return $attributes; }
The trouble with this approach is that it applies the filter to all genesis_attr_entry on the page, including featured posts in sidebar.
Noted when running page through structured data testing tool
https://developers.google.com/structured-data/testing-tool/I need to restrict the filters to the custom loop entries only, or reset them to their defaults once the loop is complete.
All pointers to the error in my ways or suggestions for alternative approach will be gratefully received 🙂
Soft launch for client today, with incomplete data http://vegleatherhub.com/directory/
My JustGiving page: https://www.justgiving.com/helping-graham-give
June 9, 2015 at 12:50 pm #155611Genesis DeveloperMemberAdd this in your functions.php file
add_action( 'genesis_entry_footer', 'gd_remove_vlhdir_filter', 20 ); function gd_remove_vlhdir_filter() { remove_filter( 'genesis_attr_entry', 'vlhdir_attributes_entry' ); add_filter( 'genesis_attr_entry', 'genesis_attributes_entry' ); }
June 9, 2015 at 4:37 pm #155632GrahamMemberOK great, thank you. That pointed me back on track
As it stands, adding that to my existing code wouldn't work as hoped. I would end up with one Organisation and the rest being CreativeWorks ,
Yet if I change the hook I use from
genesis_header
togenesis_before_entry
.. then all good.i.e.
add_action( 'genesis_before_entry', 'vlhdir_edits' ); function vlhdir_edits() { if ( get_post_type() == 'vlhdir_entry' ) { remove_filter( 'genesis_attr_entry', 'genesis_attributes_entry' ); add_filter( 'genesis_attr_entry', 'vlhdir_attributes_entry' ); // etc } } add_action( 'genesis_after_entry', 'vlhdir_remove_edits' ); function vlhdir_remove_edits() { if ( get_post_type() == 'vlhdir_entry' ) { remove_filter( 'genesis_attr_entry', 'vlhdir_attributes_entry' ); add_filter( 'genesis_attr_entry', 'genesis_attributes_entry' ); // etc } }
My JustGiving page: https://www.justgiving.com/helping-graham-give
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.