I am using a page to replace custom post type archive. I used page template in that page to query CPTs like a CPT archive

The problem is, since I conditionally load different css files based on the page, I want this page to return false to is_single() and true to is_archive() so that it won't break my conditional. How can I achieve this? What is the earliest hook I can use?

  • 1
    This is a terrible approach. Why is your archive a page template anyway? If it is a page, then why are you using the archive conditional. If it's a page, check for the page. Commented Apr 20, 2020 at 2:54
  • I want to make CPT archive a page as I want to use it as the site front page, also for the ease of management on meta title and description. Because the content it loads should belongs to an archive, therefore it needs to pass conditional for is_archive() and get those CSS
    – Winston
    Commented Apr 20, 2020 at 2:56
  • 1
    assuming the page needs to use a custom page template for the code, why do you not check developer.wordpress.org/reference/functions/is_page_template and adjust your conditional check for what CSS to load?
    – Michael
    Commented Apr 20, 2020 at 3:26
  • It will be really tedious, as I not only need to add this conditional tags for every is_archive() used, I also need to set conditional to negate every is_single() in every plugin.
    – Winston
    Commented Apr 20, 2020 at 4:38
  • What you want to do is a hack, and is more likely to introduce issues than resolve them. You want to use a page to be able to use meta descriptions etc, but setting the page to appear as is_archive() will probably stop that form working anyway. It might be tedious but it seems like you have some much larger architectural issues that need to be resolved. Commented Apr 20, 2020 at 5:19


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.