• Resolved d4jaj1

    (@d4jaj1)


    Hello,

    I use <?php echo get_permalink(); ?> in my theme files to get the current URL. What is the alternative to this (shortcode perhaps) when working in Posts/Pages??

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter d4jaj1

    (@d4jaj1)

    I’m sorry if I wasn’t clear – I need to display the url in a post/page using the post or page itself. Since you can’t run PHP when authoring posts/pages – the codex example won’t work.

    Is there a built in WP shortcode to do this?

    So you need to display this in Add/Edit Post/Page?

    Thread Starter d4jaj1

    (@d4jaj1)

    I need the URL of the current page/post so I can pass it to Digg, Yahoo Buzz, TweetMeMe, etc. If I can find some sort of shortcode, I can copy and paste the same code to each page (every page won’t have it – else Id’s just modify the. theme).

    Without this, I’ll have to manually apply the URL to each page/post in question – 4 times a page (once for each service).

    I’ve seen ExecutePHP plugins, but I’m concerned about performance and security. I’m surprised this isn’t baked into the core of WP.

    Thoughts?

    Why not create your own shortcode that grabs the current url?

    Thread Starter d4jaj1

    (@d4jaj1)

    Don’t know how. I’m assuming this is a common question, so anyone who’s already created this wheel – please feel free to post an example function.

    Thread Starter d4jaj1

    (@d4jaj1)

    Anyone?

    If you’re copying and pasting anyway, why not just copy the URL from the permalink line under the post title in the post edit screen?

    Unless i’m missing something, you want to put a link in the post that links to itself…

    Thread Starter d4jaj1

    (@d4jaj1)

    For others who were struggling with this, the answer I found is below. it works on pages and posts. Add it to your theme’s functions.php file (not the WordPress includes).

    function get_url() {
    return .get_permalink($post->ID).;
    }
    add_shortcode(‘GetURL’, ‘get_url’);

    Use this in your Page/Post – [GetURL]

    What’s the dot between return and get_permalink for?..

    As i thought though, a link to itself.. ??
    I’d have written something like the above for you had you answered my previous reply.. ??

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Get_Permalink Alternative’ is closed to new replies.