Plugins add features separately from the core WordPress system. This means you can add or remove features without touching the main WordPress code. This keeps your site safe when WordPress updates.
Activating a plugin loads its code so it can add new features or modify existing ones on your site. It does not replace core files or change themes automatically.
<?php
function my_plugin_init() {
// plugin code here
}
// Which line correctly hooks the function?
WordPress uses add_action('hook_name', 'function_name') to connect functions to events. The hook name is a string, and the function name is also a string.
In WordPress, when hooking a function, the function name must be a string. Passing it without quotes causes a PHP fatal error because it looks for a constant or variable.
By default, WordPress runs hooked functions in the order they were added with the same priority. Since Plugin 1 hooked first, its output appears before Plugin 2's output.