Get URL of current post but not the page number

I don’t think your code works as expected because you are not printing the URL of the post. Note that get_permalink() returns the permalink of current post inside a loop but doesn’t print it like the_permalink(). So, you should use <?php echo get_permalink(); ?> or <?php the_permalink(); ?>.