-
AuthorPosts
-
November 17, 2014 at 2:21 pm #352409
Hi,
I found this function which replaces the standard icon (pencil) for posts in archives: https://kriesi.at/support/topic/changing-default-pencil-for-blog/#post-294182
I only want to replace this icon for custom post type’s “business_profile” slug root archive and a custom archive template for custom taxonomy “business_category” (which displays “business_profile” posts, just like the slug-based archive).
I tried adding checks based on WP’s
is_page_template('business-custom-archive_filename.php')
andis_post_type_archive('business_profile')
, but none of the checks I tried ever returnedtrue
.Does anyone know how to limit the ‘replaces the standard icon’ function, to only replace the icon when the custom post type is displayed by any of the 2 types of WP archives*?
Thank you,
Ralph
* I mean the following 2 types of archives:
Type 1: The archive displayed when visiting a
mysite.com/custom_post_slug/
URL.
Type 2: The archive displaying the same custom posts as archive Type 1, but than via a custom taxonomy’s custom archive template based onarchive.php
(archive URL looks like:mysite.com/business_category/
).November 17, 2014 at 9:59 pm #352700Hi Ralph12!
Try this out, http://codex.wordpress.org/Function_Reference/is_tax. That should return true if your viewing an archive for a custom post type.
Regards,
ElliottNovember 18, 2014 at 2:13 am #352809Hi Elliott,
Thanks for your suggestion. I tried
is_tax
as well, but that doesn’t work either. Here’s the function (it uses a custom fontello icon, which works fine without any of theis_
-based checks):function avia_replace_standard_icon($icons) { if (is_tax('business_category')) { $icons['business_profile'] = array('font' => 'fontello', 'icon' => 'ue803'); } return $icons; } add_filter('avf_default_icons', 'avia_replace_standard_icon');
I’m clueless as to why the above function doesn’t return true for a check. I’m in fact using another
is_tax
-based function, which does return true. Here’s the code of the working function (it renames the archive’s H1 title):function archive_suit_business_category($output) { if (is_tax('business_category')) { $term = get_term_by('slug', get_query_var('term'), get_query_var('taxonomy')); $output = 'Business category: ' . $term->name; } return $output; } add_filter('avf_which_archive_output', 'archive_suit_business_category');
Do you know why the same check works for the 2nd function, but not for the 1st?
Best,
Ralph
November 18, 2014 at 6:48 pm #353163Hi!
Try something like this.
add_action( 'pre_get_posts', 'enfold_customization_change_standard_icon' ); function enfold_customization_change_standard_icon() { global $avia_config; if ( is_tax() ) { $avia_config['font_icons']['business_profile'] = array( 'font' =>'fontello', 'icon' => 'ue8f6'); } else { $avia_config['font_icons']['business_profile'] = array( 'font' =>'fontello', 'icon' => 'ue923'); } }
And replace the icon codes with whatever you need.
Regards,
Elliott- This reply was modified 10 years ago by Elliott.
November 19, 2014 at 3:16 pm #353711Thank you very much, Elliott! Your code suggestion got me in the right direction. It worked right away for the custom taxonomy-based archive, but not yet for the custom post type slug-based archive. To get that archive type working too, I added
|| is_post_type_archive('business_profile')
to the check. This is the final code, that works for both archive types:function avia_replace_standard_icon() { global $avia_config; if (is_tax('business_category') || is_post_type_archive('business_profile')) { $avia_config['font_icons']['standard'] = array('font' => 'fontello', 'icon' => 'ue803'); } else { $avia_config['font_icons']['standard'] = array('font' => 'entypo-fontello', 'icon' => 'ue836'); } } add_action('pre_get_posts', 'avia_replace_standard_icon');
Thanks again and regards,
Ralph
-
AuthorPosts
- The topic ‘Question about found function to replace standard icon for posts in archive’ is closed to new replies.