Add Extra codes by plugin

There are hooks that you can use for this purpose.

The wp_head hook allows you to add your content to the header, while wp_footer does the same for your footer.

Use it as follows:

add_action( 'wp_head', 'my_function');
function my_function (){
    echo "Hello World!";
}

This will print Hello World! in your header.

However, there is an important note. The theme must have wp_head(); and wp_footer(); in its template files. Almost every theme has these files, so you can safely use this in most cases.

To print anything in a template from a plugin, you have to actually hook to some action or filter. If there is none of these in that template file, then you simply can’t echo your content there, and must find somewhere else to do so.