page url in shortcode

Depending on how the page’s query and loop are constructed, when you access the post object from the sidebar or footer, you sometimes get the last post in the loop rather than the page itself.

You can ensure you’re getting the original (page) object by running wp_reset_query() from inside your widget (before you access the post object or run any functions that assume the current post as their target).

One caveat here: make sure there’s nothing after your widget that would be affected by this post reset.