Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9029149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:10:52+00:00 2026-06-16T07:10:52+00:00

I am trying to have two different stylesheets on my wordpress blog, so that

  • 0

I am trying to have two different stylesheets on my wordpress blog, so that one stylesheet is used when the page is accessed via the web, and the other stylesheet is used when the blog content is accessed via our iOS app. Right now we are appending ?app=true to URL requests from our iOS app in hopes that in our blog we could search for this string and load a different stylesheet. We are using a JSON API plugin so that our iOS app can programmatically pull our blog posts and display them in a web view in the iOS App.

In my wordpress blog I am using javascript that looks for ?app=true in the URL, and if so, load a different stylesheet.

<script language="javascript" type="text/javascript">
    var location = window.location.href;
if(location.indexOf("?app=true") > -1) {        
document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"appstyle.css\" />");
}
</script>

This code is placed within the tags in the header.php file of my wordpress theme.

The stylesheet that I am trying to use is called appstyle.css and is located in the same directory as header.php.

The issue that I’m having is that with this code it reloads the browser page infinitely. The issue seems to be with the document.write function, as without that the webpage loads fine (although it obviously isn’t loading the appstyle.css stylesheet).

I have also tried this if statement:

if(window.location.search.indexOf('?app=true') === 0) 

but it doesn’t seem to make a difference.

Is there a better way to load different stylesheets depending on if it is loaded in an iOS app vs the web? Is there something I am doing wrong in my code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T07:10:53+00:00Added an answer on June 16, 2026 at 7:10 am

    try:

    location === window.location
    

    in the console.

    It will output true. Which shows that the global variable location is already set and points to the current location object of window. With your code you’re changing that variable, by assigning a new value, which triggers a browser reload.

    To fix it, just use another name for your variable, e.g.:

    var currentLocation = window.location.href;
    

    Or put your code in a self-executing function, to separate it from the global scope:

    (function (){
      var location = window.location.href;
      if(location.indexOf('?app=true') > -1) {        
        document.write('<link rel="stylesheet" type="text/css" href="appstyle.css" />');
      }
    }());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a public facing interface that I'm trying to map two different enumerations
I'm trying to come up with a way combine two arrays that have different
I have two arrays of data that I'm trying to amalgamate. One contains actual
I'm structuring a database, and found that I have two different objects I'm trying
In my silverlight application I have two wcf services, that used to be one,
I have two different things that I'm trying to do. I need to change
What I am trying to do is that I have two different tables and
I am trying to have two different submit buttons. If one submit button is
I am trying to have two submit buttons in my form - one accepts
I am trying to have two data series plotted in one graph as boxes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.