You can add code into your functions.php file in child-theme or use WP Code plugin
function.php method
Appearance → Theme File Editor and select Theme Functions file in sidebar. Use child-theme otherwise snippet will be overwritten/lost after update.
WPCode plugin method
WPCode – Insert Headers and Footers + Custom Code Snippets – WordPress Code Manager
WP Code will be more suitable for most cases. Head over to WP Code, select Add Snippet and Add Your Custom Code (New Snippet)
In next step choose PHP Snippet
Paste snippet, toggle “inactive” to “active” button near Save button and Save
Done. Make sure it’s activated