rtCamp notes, day 30 of undefined

Functions to get the theme directories:

  • get_template_directory(); → This will get the directory for the parent theme if we are using child-parent structure, else it will give us the directory of the current active theme. **This will give us the path for the directory.**
  • get_template_uri(); → This follows the same pattern as the above one, just **Instead of path it will give us the URI ( URL location ) to the directory**

  • get_stylesheet_directory(); → This will get the directory for the child theme if we are using child-parent structure, else it will give us the directory of the current active theme. **This will give us the path for the directory.**
  • get_stylesheet_uri(); → This follows the same pattern as the above one, just **Instead of path it will give us the URI ( URL location ) to the directory**

Some things about the enqueuing the style/script

The third parameter for the style/script enqueue function accepts a dependencies array, which means the handle on which our style/script will depend on → our style/script will only be loaded after the dependencies have been loaded.

If we do not specify dependencies an empty array would be considered i.e. no dependencies

*They are optional to add.

If we specify a dependency and the handle does not exist, our style/script will not be enqueued to the front end.

If we specify a set of dependencies and a single one of them doesn’t exist, still our style/script will not be enqueued to the front end.

If we specify a dependency and the handle exists, but the file does not exist, our style/script will be included as it does not check for the file, it only checks for the handle.

This states that our style/script depends on all the handles we provide inside the dependencies array.

→ Version in enqueue/register

While enqueuing or registering a style/script, our fourth parameter is the version, this is used for the caching in the browser, if the URL of a style/script is same the browser caches the file at its end.

So for better usability we must use the version number of our plugin/theme for it, so that if we create an update to our plugin/theme, this would also be updated and the cache will be cleared.

If we do not pass a version number by default, the WordPress adds the WordPress version as the version for our style/script.

Leave a Reply

Your email address will not be published. Required fields are marked *