'How to add PHP code to only a certain page in wordpress

I have added styling to my anchor tag and have made the text-decoration to none to the entire website. But I want the blog section of my website to underline the links.

I'm using the code snippet plugin in wordpress as I don't have direct access to the files.

And this is the code that I'm using.

add_action( 'wp_head', function  () { ?>
    <style>
        
         a:link {
            text-decoration: underline;
        }
</style>
<?php } );

The problem is that this PHP code gets applied to my entire website which is not what I want. I only want this to be applied to the body section of the blog content.

I would love to have someone assist me with this problem.

Thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source