Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

In order to optimize my site for a bit more loading speed, I wanted to enqueue a couple of scripts only to the archives for default post type. A rough example is given below.

function my_theme_script_enqueues() {

        if (!is_admin()) {

            if ( is_archive()) {
                wp_register_script('isotope', get_template_directory_uri() . '/js/jquery.isotope.min.js', 'jquery');
                wp_enqueue_script('isotope');
            }
        }
    }

add_action (blah..blah..blah..blah)

I assumed something like (is_archive('post')) would work, but it still loads on cpt-archive and tag archives and such ( does not load on pages though).

I cant use (is_archive()) as it again loads it to every other archive types eg. cpt-archives, tags etc which is pointless to me.

If I use if (!is_post_type_archive('cpt')) {...} then it obviously goes wild and loads it everywhere else, not scalable.

I know how to use if( is_post_type_archive('post')) {...}, but it is not giving me any result, which it should i guess as 'post' is a post-type right? When I search for a solution here I get mostly threads talking about custom post type archive. Please let me know what my alternative is?

share|improve this question
    
Hi..When I said I wanted to enqueue a couple of scripts only to the archives for default post type, I actually meant that I only wanted it load only on default post type categories. But seems like I overly complicated the question which led to the (is_home()) possibility, which was not my case. I apologize. (is_category()) was a simple and so obvious solution for me. I knew I was missing something obvious. God, I feel so stupid. ! Salute to all the great folks for help anyways. –  gurung Sep 14 '13 at 9:43

2 Answers 2

up vote 3 down vote accepted

is_archive() doesn't accept any parameter and return true for every archive page: Categories, tag, date, author, .... I think what you need is to check if you are in a category page (in a archive of the category taxonomy) or in the blog home:

if ( is_category() || is_home() ) {
    wp_register_script('isotope', get_template_directory_uri() . '/js/jquery.isotope.min.js', 'jquery');
    wp_enqueue_script('isotope');
 }
share|improve this answer
    
Yes, (is_category()) did the trick. Appreciate the help. –  gurung Sep 14 '13 at 9:45
    
Doesn't this miss is_tag() etc features of the is_archive()? I find it perplexing I can't use is_post_type_archive( "post" ) to differentiate between blog posts and other post types. –  lkraav Jun 10 at 10:04
    
The standard post archive is the blog home page, so I think is_home() is the conditional you should use for is_post_type_archive( "post" ) but if you are in a tag, category, date or author archive you will need to add the proper conditionals. –  cybmeta Jun 10 at 10:18

You are probably looking for is_home().

It's inconsistent for historical reason. Concept of post type archives hadn't appeared until after there were actually custom post types to have archives for.

The basic index list of blog posts is is_home() and somewhat confusingly it's not even is_archive().

share|improve this answer
    
I've deleted my answer. Always thinked is_home() works if posts page is setted. Upvoted for teach me this. –  G. M. Sep 14 '13 at 9:21
    
@G.M. yeah, the naming and logic around is_home()/is_front_page() is unholy mess. The modern meaning for is_home() is archive of post post type, but it's neither called that, neither archive. sigh –  Rarst Sep 14 '13 at 9:29
    
What confused me is the fact that activating pretty permalinks there is no way to have a generic archive of standard post type without setting the posts page. Sure home_url() works... until I set a front static page. –  G. M. Sep 14 '13 at 9:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.