Archived topic
sharing link based on function urlencode(get_permalink())) does not work on blog
3 replies · Started by Anonymous on August 2, 2015
Hi,
Is there a reason that the refenced function does not encode correctly the URL of the blog start page (different from start page) but rather results in the address of the last post shown?
See links generated behind the sharing links in the middle text widget of http://www.pm-berger.de/blog.
For individual apges or posts the same function works correctly though.
Best regards
M.
The only place I see sharing links on the blog is in the footer - are those the ones you mean?
If so, the footer is out of the "loop", so the get_permalink() function may act funny.
You may have to get the $post global as explained here: https://tommcfarlin.com/get-permalink-outside-loop/
Hi Tom,
since I am not a PHP expert at akll, perhaps you are able to help me out slightly more?
I have added the function
function my_get_permalink() {
global $post;
get_permalink($post->ID);
}
to the file functions.php of my child-theme.
Then I am trying to use <?php echo urlencode(my_get_permalink()); ?> instead of <?php echo urlencode(get_permalink()); ?> but the result is an empty string.
Did I miss anything?
Best regards
M.
Hmm, his code seems to be a little off.
Try this:
function generate_custom_permalink() {
global $post;
echo get_permalink($post->ID);
}
Then use: generate_custom_permalink()
