Is this the correct way to define multiple custom variables?

The code is similar to this one. But I am defining the variables before using them. Open graph for images in multipage posts - #4 by jmooring. I have edited the code in my first comment.