24+ Reasons Code Doesn’t Work & How To Fix It

I always test code first to make sure it works however there are many reasons it doesn’t work sometimes for both myself and other people who use it even though it isn’t broken.

Here’s a list of some of the reasons code doesn’t work:

  1. Forgot to clear the browser cache: You may make CSS changes and think they don’t work when they actually do because the browser is actually displaying an older version of pages which include the older code. Clear your browser cache to make sure.
  2. Didn’t clear the server cache: Some Managed Hosting providers use very aggressive server side caching. I know WPEngine do meaning it can actually take days before CSS changes appear on your site. You may make these changes which really work but think they don’t because you can’t see the changes on the front end. Clear your server cache and test the code locally of using server side caching or a caching plugin.
  3. Pasted CSS code into the functions file: CSS code doesn’t work properly in the functions file which includes an opening PHP tag meaning its read by a PHP processor installed on the server.
  4. Pasted PHP into the style sheet: PHP code doesn’t work in a .css file which is read by a browser and not a PHP processor installed on the server.
  5. Pasted PHP or CSS into the header and footer scripts: Themes which include a box for header and footer scripts do so to make it easy to adds Javascript for Google Analytics tracking and live chat scripts, not PHP scripts.
  6. Copied it from a web page and pasted it into the theme editor: Very common mistake that can cause the Apostrophes to turn around resulting in the white screen of death which breaks your site. Always copy the raw code and paste it at the end of the file using a text editor like Notepad++.
  7. Didn’t copy all of the code: Copying a block of CSS code which doesn’t include the class or misses a closing bracket will result in the code not working. So you may think the code is no geed when the only problem is you left a bracket or semi colon behind.
  8. Didn’t paste all of the code: Same as above and does happen sometimes.
  9. Used the new hooks when your theme uses the old ones: Using code which includes Loop hooks for sites still running the old XHTML markup on new sites doesn’t work. The code will work on older sites so it isn’t broken, but it won’t work on HTML 5 enables child themes.
  10. Used the old hooks when your theme uses the new ones: Same as above
  11. Using an old browser which doesn’t support the classes in the code: Some older browsers don’t support certain CSS classes meaning the code will not do what its written for. You can install several browsers to test the code or use free online tools for cross browsers compatability.
  12. Using the latest browser version which doesn’t yet support the classes in the code: Some new browsers don’t support some CSS classes meaning the code will work on older browsers however you may think it doesn’t because you’re using a beta version or the latest version which has only just bee released.
  13. Copied the opening PHP tag and pasted it into your functions file: PHP snippets generally include an opening PHP tag however this shouldn’t be pasted into a functions file which already includes that tag. You will get an error message and break your site if this happens which is easy to fix simply by removing the tag. This is the reason its always best practice to use a text editor to paste the code into the actual file rather than use the WordPress them editor. If you add the code to the actual file, you can easily re-open it and remove the problem quickly which isn’t the case if using the theme editor as you will be locked out of the site when you suffer a programming error.
  14. Copied and pasted both solutions rather than choose one: Many posts and forums include multiple code snippets which solve the same problems. If you paste 2 code snippets which do the same thing, it can break your site so you may think the code is broken which isn’t the case. Only use one snippet at a time.
  15. Copied functions code into a template file: Sometimes you’ll find PHP code which has been written to be used in a template file rather than a child themes functions file. Template code doesn’t always work in a functions file as its generally wrapped in PHP opening and closing tags. Custom functions generally aren’t meaning they generally won’t work in a te,plate file depending on the theme. Simply make sure you know exactly which file to paste the code in otherwise you may receive an error thinking the code doesn’t work when it does.
  16. You have a plugin installed that over rides the code: Some plugins over ride PHP code meaning code with filters and hooks may not work. An example of this is the Genesis Simple Edits plugin. If you have this plugin installed which enables you to customize the post info and post meta, adding PHP code to do the same thing which includes a post meta or post info filter won’t work. You may think the code doesn’t work when in fact it does and all you need to do to solve the problem and get the code to work is deactivate the plugin.
  17. Using PHP code to change the layout conditionally This code will not work on some themes using bbPress which also use the Genesis bbPress connect plugin. This plugin hooks into the Genesis filters which is the same thing PHP code does to change layouts conditionally so it will not work as it over rides the code.
  18. Using XHTML CSS classes on HTML 5 child theme – Example: #content will not work on a HTML 5 child theme which uses .entry-content.
  19. Using HTML markup on a XHTML theme – .site-header will not work on a site running XHTML markup so you need to use #header.
  20. Front Page Template Code – Any code in your front-page template only works when you use the default Reading Settings. If you change these settings and select a Static Page as your front page, the code in your front page template will not work.
  21. Added CSS After Media Queries – Best to add custom CSS before your Media Queries otherwise it may not work.
  22. Added CSS to Modify Class Already Styled – You added CSS at the end of your style sheet to change the styling of an existing element which is already styled by default. An example of this is when you modify a widget area to use the Genesis featured posts widget when its styled by default to use the featured page widget. Your CSS may be different but you are using a different class. What you ned to do is modify the default CSS so it on longer styles the featured page widget and only styles the featured post widget.
  23. Home Page Template Code – Any code in your home.php template file, will only work on the front page when you use the default Reading Settings. If you use a static page as your Front Page, the code will only work on your posts page (like a blog page) if you haven’t selected the blog page template from the drop down menu. (Only applies to themes with include a blog page template).
  24. Incorrectly modified CSS Makes Other CSS Break – A member installed some code to create a custom layout but it didn’t work because the CSS to modify the content width didn’t work. They discovered other CSS they added previously using !important prevented the new CSS working.

The above code will NOT work if you also have the Genesis Simple Edits plugin activated as it over rides the post info filter.

That’s all i can think of at the moment but am sure there’s many more reasons code doesn’t work (but really does) which could be added to this list.

Related Posts


Comments

One response to “24+ Reasons Code Doesn’t Work & How To Fix It”

  1. […] 16+ Reasons Code Doesn’t Work & How To Fix It – I always test code first to make sure it works however there are many reasons it doesn’t work sometimes for both myself and other people who use it even though it isn’t broken. […]

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.