WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Get Permalink (2 posts)

  1. jennifer2010
    Member
    Posted 2 years ago #

    Hi Everyone :)

    I'm using the following code placed in my functions.php file in order to grab the permalink for usage with a shortcode. The problem is it requires me to specify a post ID for it to work, instead of just grabbing the permalink automatically. [permalink id=49]

    How can I edit the code so that it returns the permalink automatically without having to manually add the ID every time?

    Thank you so much!

    function permalink_thingy($atts) {
    extract(shortcode_atts(array(
    'id' => 1,
    'text' => "" // default value if none supplied
    ), $atts));

    if ($text) {
    $url = get_permalink($id);
    return "$text";
    } else {
    return get_permalink($id);
    }
    }
    add_shortcode('permalink', 'permalink_thingy');

  2. jennifer2010
    Member
    Posted 2 years ago #

    Resolved:

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

    Shortcode is [GetURL]

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.