• Resolved neotrope

    (@neotrope)


    Hi, just getting in to setting this up with our many year old YOURLS install (we were using custom CMS since 2005 on our main site, now moving to WordPress, and going to connect to autogen the shortcodes so I don’t have to do them by hand, which has gotten super tedious). *THANK YOU* for this plugin.

    ANyway…
    is there a shortcode/hook to echo the shortcode from YOURLS in the post template, as we need to put in our own custom social sharing links using the shortcode vs the base WP URL/permalink for story/news item.

    I am just starting this, so apologies if I haven’t gotten far enough in yet to see whether or not this plugin replaces the default WP shortcode, say when printing that in the head area by default based on story ID, which seems unlikely. 🙂

    So, we’re going to setup our reponsive social links like
    a href=twitter ?url=[yourlsshorty] (not actual code, obviously)

    Is that doable? Happy to donate to plugin/tip jar 🙂
    (which I will do anyway, btw)

    Thanks!

    https://wordpress.org/plugins/yourls-link-creator/

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?

    Thread Starter neotrope

    (@neotrope)

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

    Thread Starter neotrope

    (@neotrope)

    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 🙂

    Thread Starter neotrope

    (@neotrope)

    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>

    Thread Starter neotrope

    (@neotrope)

    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

    Thread Starter neotrope

    (@neotrope)

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

    Thread Starter 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.

    Thread Starter 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)
  • The topic ‘Echo/print shortcode URL on the post for social media links’ is closed to new replies.