Filtering meta on CPT
-
One of the Twenty Twenty template tags defined in template-tags.php is a filter that controls which post types ought to omit the display of associated meta.
Starting on line 235:
/** * Filters post types array * * This filter can be used to hide post meta information of post, page or custom post type registerd by child themes or plugins * * @since Twenty Twenty 1.0 * * @param array Array of post types */ $disallowed_post_types = apply_filters( 'twentytwenty_disallowed_post_types_for_meta_output', array( 'page' ) ); // Check whether the post type is allowed to output post meta. if ( in_array( get_post_type( $post_id ), $disallowed_post_types, true ) ) { return; } $post_meta_wrapper_classes = ''; $post_meta_classes = '';
But how to use this filter?
Let’s say I have registered a custom post type called ‘qualia’ and would like to use this filter to prevent meta from displaying. I can add ‘qualia’ to the array in the filter definition, like so:
$disallowed_post_types = apply_filters( 'twentytwenty_disallowed_post_types_for_meta_output', array( 'page', 'qualia' ) );
This is effective but seems wrong because the next theme update will overwrite template-tags.php.
My question is, how to make use of this filter in the child theme? Where to place the filter and how to correctly pass ‘qualia’ to it?
- This topic was modified 4 years, 5 months ago by .
- This topic was modified 4 years, 5 months ago by .
The page I need help with: [log in to see the link]
- The topic ‘Filtering meta on CPT’ is closed to new replies.