Support » Plugin: YOURLS Link Creator » Echo/print shortcode URL on the post for social media links

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Andrew Norcross

    (@norcross)

    there isn’t a shortcode display, but there is a function to output the URL anywhere you want. if you call get_yourls_shortlink with the post ID, it will return the shortlink if one exists. you can pass a second parameter of true and it will echo out instead of returning. does that help?

    Sweet. I don’t suppose you have an example snippet of example code to demo that (also useful for the plug docs, so helpful to all!) 🙂

    I guess this would be “inside the loop” for one use, but also “outside the loop” as well … ?

    If no time to mess with that, I’ll give it a go when I get there.

    (thanks again!)

    oh, btw – link to the “donate to this plugin” is broken here in the plugin repo.

    Plugin Author Andrew Norcross

    (@norcross)

    are you looking for a shortcode, or just an actual function setup to call? And is this going to be in the WP editor or in a template file itself?

    oh, and thanks about the donate link. fixed it 🙂

    Well, trying to figure out how to echo the generated shortcode for permalink into a set of social media links for the article, where we are hand coding the social media links directly into post template vs using plugin (redundant).

    SO, idea is if we had the normal set of social media links for stuff like twitter, facebook, g+, pinterest, linkedin and stumbleupon, we need to put the Yourls shortcode in the /+url= spot for each item/button we setup.

    eg.,

    <a href="http://twitter.com/home?status=(echo-TITLEHERE) [insert the YOURLS shortcode here] @send2press" title="Share on Twitter" target="_blank" class="btn btn-twitter"><i class="fa fa-twitter"></i> TWEET</a>

    where we would put the shortcode for the URL from the plugin there; I guess if the plugin is writing the shortcode URL to a data field we could echo that meta field for the ‘current post’ there?

    Sorry … just looking for some “ok, you put butter on toast” before I get to actually trying this (on upcoming Saturday I will be messing with this in detail …).

    Plugin Author Andrew Norcross

    (@norcross)

    OK. using your code, I would do something like this:

    <a href="http://twitter.com/home?status=(echo-TITLEHERE) <?php get_yourls_shortlink( get_the_ID(), true ); ?> @send2press" title="Share on Twitter" target="_blank" class="btn btn-twitter"><i class="fa fa-twitter"></i> TWEET</a>

    To quote Austin Powers with his foot on the side of the tub …
    “that’s the spot…. yeahhhh!” 🙂

    Thanks, that was the shortcode .. um .. .shortcode … I was seeking to use as the starting point.

    Now, let’s see if I can send you a donation somewhere :-0

    (oops, guess I should not have put my real twitter account ID in there .. just got some weird notice from wordpress.org about my account ID being used … funny ….)

    neotrope

    (@neotrope)

    I am super rusty at this stuff….
    trying to see if it makes sense to limit “queries” if we have 6 social media buttons to do

    something like

    <?php {
        global $post;
        $yourl = get_yourls_shortcode($post->ID);
        $yourl = esc_url($youurl);
    }?>
    <a href="http://twitter.com/home?status=(echo-TITLEHERE) $yourl @tweetacct" title="Share on Twitter" target="_blank" class="btn btn-twitter"><i class="fa fa-twitter"></i> TWEET</a>

    Not sure correct syntax for that first bit. Any suggestion? Trying to “optimize” having that query run on every post page for news portal which is 16 years old and high traffic (well, relative to some). So, thinking is does it make sense to do one query, then re-use that 6 times, vs 6 individual “get” elements ?

    Sorry, super rusty. Last time I rolled my own stuff and loops/queries in depth was 2011, so it’s like learning to ride a motorcycle again after getting spoiled by drag/drop site builder crap. 🙂

    Thank you again for your time 🙂

    If you ever feel inclined to make a dead-simple social sharing buttons plugin that hooks in the Yourls shortcode, in essence that is what I’m doing except doing this in the single.php template vs using plugin.

    Plugin Author Andrew Norcross

    (@norcross)

    it’s hard to say without seeing the entire function you have built for the social stuff, but the below code would create the shortlink as a variable that you can use later:

    <?php
    global $post;
    $yourlslink = get_yourls_shortlink( $post->ID, false );
    ?>

    so you could just echo it out later.

    neotrope

    (@neotrope)

    Awesome, I’ll give that a go — I think the false element was what I was missing in there

    so could do something like this for the bottom of posts…

    <?php
    global $post;
    $yourlslink = get_yourls_shortlink( $post->ID, false );
    ?>
    <a href="http://twitter.com/home?status=(echo-TITLEHERE) $yourlslink @tweetacct" title="Share on Twitter" target="_blank" class="btn btn-twitter"><i class="fa fa-twitter"></i> TWEET</a>
    (etc.)

    where the (echo-TITLEHERE) is real WP echo the permalink, not the shorthand I did there ;-0

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