Where to add add_rewrite_tag for trailing tilde?

Ive just been reading @gmazzap s reply about wordpress matching URLs with trailing tildes.

and could do with some help please. As a coding newbie, I am not sure where to add his suggested code:

add_action('init', function() {
  add_rewrite_tag( '%postname%', '([^~/]+)', 'name=' );
});

Functions.php, /includes/rewrite.php, or somewhere else...

Also what are the implications of doing this, when wordpress updates, will these changes be lost? Am running a child theme. Sorry to ask such basic questions. Thanks for your help.

Topic rewrite-tag Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.