On occasion, plugins need to refer to external files (for example, images, JavaScript, or jQuery script files) that are stored in the plugin directory. Since users are free to rename a plugin's folder or even install plugin files straight into the WordPress plugin directory, paths to any external files must be built dynamically based on the actual plugin location. Thankfully, a number of utility functions are present to simplify this task. In this recipe, we will write a simple plugin that will add a favicon meta tag to a website's header, pointing to an image file located in the plugin directory.
- Navigate to the WordPress plugin directory of your development installation.
- Create a new directory called
ch2-favicon
. - Use a web service, such as http://getfavicon.org, to retrieve a website's favicon (for example,
http://www.packtpub.com
) and store it in the plugin directory with its default name (favicon.ico...