[Resolved] sharing link based on function urlencode(get_permalink())) does not work on blog

Home Forums Support [Resolved] sharing link based on function urlencode(get_permalink())) does not work on blog

Home Forums Support sharing link based on function urlencode(get_permalink())) does not work on blog

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #125685
    Mike A. Spell

    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.

    #125730
    Tom
    Lead Developer
    Lead Developer

    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/

    #125979
    Mike A. Spell

    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.

    #126012
    Tom
    Lead Developer
    Lead Developer

    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()

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.