Hi All,
I almost have the quote machine done, but I’m not sure if I’m approaching the Twitter button the right way.
For my HTML I currently have this…
<a class="float-left" href="#" target="_blank"><i class="fa fa-twitter-square" aria-hidden="true"></i></a>
I believe I need the ?text bit to actually have the quote show up when I click on the Twitter icon; however, I need to somehow load in that text into this URL when a user clicks the Twitter icon.
So with that I tried using some JS to load that into the href so I have this…
var tweetMsg;
$.ajax ( {
type: 'GET',
url: 'https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1',
success: function ( data ) {
tweetMsg = $( ".message" ).html( '<blockquote><h3>' + data[0].content + '</h3></blockquote>' );
$( ".author" ).html( '<strong> –' + data[0].title + '</strong>' );
},
error: function () {
$( ".message" ).html( '<h3>Dev messed it up!</h3>' )
},
cache: false
} ); // end ajax
$( "a" ).attr("href", "https://twitter.com/intent/tweet?text=" + tweetMsg);
} ); // end btn
But after testing this it doesn’t look like the var tweetMsg actually captures the quote. So am I overthinking this? Am I on the right track? If so how would I be able to store the value of the quote in a variable or would I use something else?
Thanks!
Seth