Does anyone have good programming experience for best practices with Themeforest HTML/WordPress theme uploads?

Panther28

Elite Member
Executive VIP
Jr. VIP
Joined
May 2, 2010
Messages
9,937
Reaction score
16,034
I've finished a theme, and I would be grateful to anyone who maybe sells themeforest themes there already.

What are the best practises, for both a HTML, and then a WP theme?

Should I name all my javascript functions, with plugin_name_business_name_function_name, to avoid conflicts (something like that, I'm not even sure where I got that idea! lol)

And what about for example, the ID's and class names, do those have any impact? What else I maybe need to think about?

What are some good resources if anyone has them that might be helpful to look at. I looked at the Envato elements page for theme forest, but it's very old and not updated regularly.

Cheers
 
just add a unique shortcut of your business name as the prefix.
for example, the plugin the SEO framework will add tsf_ to all its functions to avoid conflicts.
the GeneratePress theme has generate_ as the prefix to all its functions.

for IDs and Classes, you can also add a prefix to be on the safe side. For the fact that you are selling a theme, you shouldn't be worrying too much about ID/Class conflicts as only one theme is activated at one time.
 
I've finished a theme, and I would be grateful to anyone who maybe sells themeforest themes there already.

What are the best practises, for both a HTML, and then a WP theme?

Should I name all my javascript functions, with plugin_name_business_name_function_name, to avoid conflicts (something like that, I'm not even sure where I got that idea! lol)

And what about for example, the ID's and class names, do those have any impact? What else I maybe need to think about?

What are some good resources if anyone has them that might be helpful to look at. I looked at the Envato elements page for theme forest, but it's very old and not updated regularly.

Cheers

Hey @Panther28,

To be honest, I wouldn't sell your theme on TF as the process of having your theme listed is pretty rough + they are taking LOADS of money from you.
My best call would be to make a free theme, list it on WordPress.org make a pro-addon such as Astra Pro add-on, and sell it as a premium plugin.
The same goes for GeneratePress Premium and all other add-ons that make a free theme more feature-rich.
From my experience, people will be paying more money = the higher income for the developer. =)
 
As far as CSS class names are concerned you shouldn't worry too much about that since it's your theme and other plugins shouldn't be overriding your theme unless it's on purpose. Have you seen this before? It's a pretty good reference that I think is still relevant: https://www.wpbeginner.com/wp-themes/default-wordpress-generated-css-cheat-sheet-for-beginners/

As far as JavaScript goes, it sounds like you are concerned about having functions globally availably like get_page() and maybe somebody else will also load JS with that same function name. With JS its all about closure, so what I would do is keep all your code in the same scope like this:

JavaScript:
(function () {
  let doSomeShit = (a, b)=> {
      return a+b;
  }
})();

Or you could do something like this if you wanted to make some object globally accessible:

Code:
const someThing = (function () {
    function helloWorld() {
        console.log('Hi');
    }
    
    return {
        someShit(a,b) {
            return a+b;
        },
        text: 'Hello'
    }
    
})()
 
Back
Top