0

How do I add a version number correctly?

I have checked wordpress codex but their wp register style function looks different than mine and I don't want to break anything.

Here is mine

wp_register_style( 'customStyles', plugins_url( 'css/custom-styles.css', __FILE__ ) );

Here is WordPress codexs'

wp_register_style( string $handle, string|bool $src, string[] $deps = array(), string|bool|null $ver = false, string $media = 'all' )

Is this correct?

wp_register_style( 'customStyles', plugins_url( 'css/custom-styles.css', FILE ) $ver = 301 );
4
  • Just add the required argument. Is there something specific you don't understand? Commented Nov 29, 2021 at 3:19
  • wp_register_style( 'customStyles', plugins_url( 'css/custom-styles.css', FILE ) $ver =301 ); yeah I don't understand how to properly add the version number.
    – user196941
    Commented Nov 29, 2021 at 3:21
  • Not to be rude but this is a very basic PHP question. I suggest reviewing some introductory PHP information if you plan on making code changes to your site. You just need: wp_register_style( 'customStyles', plugins_url( 'css/custom-styles.css', __FILE__ ), array(), 301 ); Commented Nov 29, 2021 at 4:03
  • Yes, I know I like taking everything in and then going from there. Even simple PHP questions. Thank you for taking the time to read and commment.
    – user196941
    Commented Nov 29, 2021 at 19:57

1 Answer 1

0

I think the issue here is how to read the documentation. The bold code at the top shows how the function is declared by WordPress, not how to use it.

Let's break it down:

wp_register_style( 
    string $handle, 
    string|bool $src, 
    string[] $deps = array(), 
    string|bool|null $ver = false, 
    string $media = 'all' 
)

Every possible variable has it's type in front. If more than one type is accepted, they are listed with a | between them. string[] means an array of strings. You do not have to use the parameter names when you use the function.

So if you want to use such a function, you can just pass the required values in the same order as in the declaration, and with the same type of course:

wp_register_style( 
    'darkmode', 
    get_template_directory_uri() '/darkmode.css', 
    [], 
    '3.2' // the version! 
);

Parameters with default values, like here $media = 'all', can be omitted completely.

1
  • Really appreciate you taking the time to explain that. Thank you
    – user196941
    Commented Nov 29, 2021 at 20:00

Your Answer

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