Did you try copying/pasting the code from my example above without editing it? Those 2 example works fine for me so I find it strange that it would throw an error on your side. Have you edited the theme files in any other way?
As to the second option, I tried putting it in a few places and each time, it made my entire back-end stop working.
The first option should be placed on loop-blog.php
The second option should only be placed in the functions.php. Adding it at the end of the file should be safe.
Don’t use both code at the same time. I recommend going with the 2nd option, editing the functions.php (using a child theme would be best)
If on your test no change is showing and you are using a caching plugin then it could be a caching issue where an old copy of the page is shown instead of reflecting the changes.
As with any change involving editing theme files, using a child theme is best practice. It’s not required as long as you know the risks of not using one.