get_permalink post id outside loop
-
Hi,
I’ve been struggling with this question for a while and altho there’s some topics regarding this subject I’m not sure how to implement it. It’s regarding social buttons on homepage sharingthe articles clicked on.
I have to use
<script type="text/javascript" charset="utf-8" >var bShareOpt = {url: "<?php echo get_permalink(); ?>"};</script>
which shows the permalink of the last ID instead of the link clicked on. If I add the post_id number<?php echo get_permalink(2926); ?>
it shows the correct post.Now this is because it happens outside the loop.
Other topics regarding getting post id outside the loop:
get-a-posts-id
wordpress-get-the-page-id-outside-the-loop
accessing-post-id-outside-of-the-loop-for-listing-child-pagesUsing
get_queried_object_id
orget_queried_object
is apparently another option to do so.But unfortunately my PHP knowledge is very limited in order to glue the pieces together. I appreciate any help!
- The topic ‘get_permalink post id outside loop’ is closed to new replies.