13 Reasons Why my code is not working

Published on:

I always test code first to make sure it works; however, there are many reasons it does not sometimes work for both myself and other people who use it even though it is not broken. In this article, I am sharing 13 Reasons Why my code is not working

Table of Contents

Here is a list of 13 Reasons Why my code is not working:

1. Forgot to clear the Browser Cache or Server Cache – Reasons Why my code is not working

Browser Cache: You may make CSS changes and think they do not work when they do because the browser is displaying an older version of pages that include the older code. Clear your browser cache to make sure.

Server Cache: Some Managed Hosting providers use very aggressive server-side caching. I know WPEngine does, meaning it can take days before CSS changes appear on your site.

You may make these changes that work but think they do not because you cannot see the changes on the front end. Clear your server cache and test the code locally using server-side caching or a caching plugin.

CSS code in to functions file: CSS code does not work correctly in the functions file, including an opening PHP tag meaning it has been read by a PHP processor installed on the server.

PHP code into the style sheet: PHP code does not work in a .css file read by a browser and not a PHP processor installed on the server.

PHP or CSS into the header and footer scripts: Themes that include a box for header and footer scripts do so to make it easy to add Javascript for Google Analytics tracking and live chat scripts, not PHP scripts.

3. Copied it from a web page and pasted it into the theme editor – Reasons Why my code is not working

Widespread 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++.

4. Did not copy all of the code or Did not paste all of the code – Reasons Why my code is not working

Did not copy all of the code: Copying a block of CSS code that does not include the class or missing 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.

Did not paste all of the code: Same as above and sometimes happened.

5. Use the new hooks when your theme uses the old ones or Use the old hooks when your theme uses the new ones – Reasons Why my code is not working

Use the new hooks when your theme uses the old ones: Using code that includes Loop hooks for sites still running the old XHTML markup on new sites does not work. The code will work on older sites, so it is not broken, but it will not work on HTML 5 enables child themes.

Use the old hooks when your theme uses the new ones: Same as above.

6. Using an old browser that does not support the classes in the code or Using the latest browser version which does not yet support the classes in the code – Reasons Why my code is not working

Using an old browser that does not support the classes in the code: Some older browsers do not support certain CSS classes meaning the code will not do what it is written for. You can install several browsers to test the code or use free online tools for cross browsers compatibility.

Using the latest browser version which does not yet support the classes in the code: Some new browsers do not support some CSS classes meaning the code will work on older browsers; however, you may think it doesn’t because you are using a beta version or the latest version which has only just bee released.

7. Copied the opening PHP tag and pasted it into your functions file – Reasons Why my code is not working

PHP snippets generally include an opening PHP tag; however, this should not be pasted into a functions file that 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 why it is 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 is not the case using the theme editor, as you will be locked out of the site when you suffer a programming error.

8. Copied and pasted both solutions rather than choose one or Copied functions code into a template file – Reasons Why my code is not working

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 that do the same thing, it can break your site, so you may think the code is broken, which is not the case. Only use one snippet at a time.

Copied functions code into a template file: Sometimes, you will find PHP code that has been written to be used in a template file rather than a child themes functions file. Template code does not always work in a functions file as it is generally wrapped in PHP opening and closing tags.

Custom functions generally are not, meaning they will not work in a template file depending on the theme. Make sure you know exactly which file to paste the code in; otherwise, you may receive an error thinking the code does not work when it does.

9. Using PHP code to change the layout conditionally or Using XHTML CSS classes on HTML 5 child theme or Using HTML markup on a XHTML theme – Reasons Why my code is not working

Using PHP code to change the layout conditionally: This code will not work on some themes using bbPress, which also uses 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 overrides the code.

Using XHTML CSS classes on HTML 5 child theme – Example: #content will not work on a HTML 5 child theme which uses .entry-content.

Using HTML markup on a XHTML theme – .site-header will not work on a site running XHTML markup so you need to use #header.

10. Front Page Template Code or Home Page Template Code – Reasons Why my code is not working

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, your front page template code will not work.

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 have not selected the blog page template from the drop-down menu. (Only applies to themes that include a blog page template).

11. Added CSS After Media Queries or Added CSS to Modify Class Already Styled – Reasons Why my code is not working

Added CSS After Media Queries – It is best to add custom CSS before your Media Queries; otherwise, it may not work.

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 that is already styled by default. An example of this is when you modify a widget area to use the Genesis featured posts widget when it is styled by default to use the featured page widget.

Your CSS may be different, but you are using a different class. You need to modify the default CSS, so it no longer styles the featured page widget and only styles the featured post widget.

12. You have a plugin installed that overrides the code – Reasons Why my code is not working

Some plugins override 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, will not work.

You may think the code does not work when it does, and all you need to do to solve the problem and get the code to work is deactivate the plugin.

13. Incorrectly modified CSS Makes Other CSS Break – Reasons Why my code is not working

A member installed some code to create a custom layout, but it did not work because the CSS to modify the content width did not work. They discovered other CSS they added previously using! Important prevented the new CSS from working.

That’s all I can think of now, these are the Reasons Why my code is not working, but I am sure there are many more reasons code doesn’t work (but does) that could be added to this list.

Some Useful Links
1. [MUST HAVE] Best 300+ Free Tools & Free Resources For Digital Entrepreneurs
2. 10 Projects for Beginners to Practice HTML and CSS Skills
3. Why we all should have a blog? – Some Benefits of Blogging
4. 10 Java project ideas for Beginners
5. 25 Java project ideas for intermediate and advanced users

Keywords

  • Reasons Why my code is not working
Related Articles

Related

Leave a Reply

Please enter your comment!
Please enter your name here