Twitter share button doesn't forward custom text - button

I'm working on a website with twitter share option for each specific product.
I followed twitter API instructions for tweet-sharing, and everything works fine except custom display of text. For example I want user to tweet like this:
"What do you think? Should I buy this? http://url.etc #mywebsite"
but all I get when user tweets is the link:
http://url.etc
This is the code:
<script type="text/javascript" src="//platform.twitter.com/widgets.js"></script>
<a target="_blank" href="https://twitter.com/share" data-url="http://bit.ly/twitter-api-announce" data-via="testtest" data-text="What do you think? Should I buy this? " data-count="none" data-counturl="http://groups.google.com/group/twitter-api-announce" >TWITTER</a>
The problems seems to be with data-text option.
Any experience on this? Ideas?
Thanks

On Wordpress I just used Tweet
Works like a charm!

simply use a link like :
tweet
Just change what is between [] (and remove them)
note that everything have to be RFC (with weird chars such as 'space' replaced by %20 etc.)
twitter propose a nice page to make the buttons
https://about.twitter.com/resources/buttons#tweet
But my solution avoid the javascript to force the design of the buton

You can use this:
<a href='https://twitter.com/share?url=google.com&text=Signup>Tweet</a <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src='//platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document,'script','twitter-wjs');</script>

Confirm that you have included the correct twitter scripts . Better still, generate your tweet button code from the twitter developer interface here ..
https://about.twitter.com/resources/buttons
If you would like to modify the tweetbutton content on the fly ...e.g after page load, you will have to creat and insert your tweet button into the html DOM dynamically .
Some guidance on that can be found here .
http://denvycom.com/blog/twitter-button-with-dynamic-custom-data-text-message/
Hopefully this is helpful.

You have to encode your text before inserting it in the link. The correct procedure is:
Encode the text with an online tool like this one
Put the result inside an HTML link (as suggested by #FenixAoras): Share on Twitter
If you generate your HTML with php, you can use the urlencode function directly in your script:
echo "Share on Twitter";
If you are using WordPress, the best way is creating a shortcode, beacuse with it you can use also the native functions of WordPress:
function tweet_this($atts, $content = null)
{
extract(shortcode_atts(array(
"text" => ''
), $atts));
return "<a href='https://twitter.com/intent/tweet?text=".urlencode( $text." - ".get_the_title()." - ".get_permalink() )."'>Share on Twitter</a>";
}
add_shortcode( 'tweet_this', 'tweet_this' );
(Note: the code above is just a lead, you can expand it and you have to test)
Usage:
[tweet_this text="my custom text with #hashtag and #Mention"]

Related

woocommerce display tag description on product page

I looked around for a while today for a way to display a tag description on the product page. But could not find a close answer to my issue of displaying a tag description.
I know if you have more than one tag on a page and it pulls in all tag descriptions would not be good for SEO or page look but I believe we are only pulling in one tag that contains a description, the rest are generic tags without a description.
Where should I be looking at how this can be done? I'm sure this is a common woocommerce mod and I'm not using the correct woocommerce terminology. Here is the info currently being displayed on our product page.
----current----
Tag - Rose Quartz
----desired-----
Tag - Rose Quartz
This beautiful pink stone is well-known for the loving powers that it
gives off. This is the stone of love, but more crystal experts see it
as self-love, self-esteem, and acceptance of one’s true self. Rose
quartz also helps to ward off any resentment that the wearer has in
their lives that have built up over time. This stone brings strength to
the heart.
So I figured out how this can be done and would like to share my findings. You will need to first have a way to add snippets to your page. I used a plugin called XYZ PHP Code, this plugin allows me to create PHP snippets to be used in elementor page builder.
I created a new snippet in XYZ named "tagdesc" and used the following code to display tag descriptions.
<?php
$posttags = get_the_terms( get_the_ID(), 'product_tag' );
if ($posttags) {
foreach($posttags as $product_tag) {
echo $product_tag->name;
echo $product_tag->description;
}
}
?>
Save and use your snippet in my case it was called [xyz-ips snippet="tagdesc"].
This will display all the tag names and descriptions of that product. In my case I removed (echo $product_tag->name;) as I did not need to show the tag name. This works in our case as only one tag has a description, I feel a better solution would be pulling out a description from a single product attribute using a similar method but have not found a solution that works.

Want to remove "background" text

How can I remove the text background=""> from my Wordpress site?
The address is https://www.mybestroadbikes.com
Thanks!
You need to delete if from the page source itself.
Here is where is the extra String
Hope this helps :)
EDIT:
I am not sure how you page is structured in WordPress but you can try when you are on the home page just click Edit Page in the top menu.
After that you will ed up in a Dashboard window with some RichTextBox on it. On the right side you have to option to switch to Text instad of Visual. When you do that I think you will be able to locate the extra String and remove it:
Please check your body tag in header.php
The tag must must have been closed incorrectly.
You've got an issue with whatever mechanism you have used to insert Google Tag Manager. Use another method to whatever you have used or check your syntax because there's a syntax error with it. You can easily embed the script in the header using the hook wp_head.
function child_theme_head_script() { ?>
<script>
//Script here
</script>
<?php
}
add_action( 'wp_head', 'child_theme_head_script' );

Target="_blank" not working

Im develope website with wordpress, Im use plugin Magge Short code
I want to create a "link" with shortcode Magee. Here is my current code
[ms_social icon_size="25px" title="Instagrame" target="_blank" icon="fa-instagram" iconcolor="" effect_3d="yes" backgroundcolor="" iconboxedradius="normal" iconlink="https://www.instagram.com/" class="" id=""][/ms_social]
Everything works except _blank attribute, even putting "_blank". Can anyone help me fix my code to the link opens in a new tab?
Thanks!
Try this one
plugin :magee-shortcodes/shortcodes/class-social.php
line number: 71 or find this below code and add
target="_blank"
$html=sprintf(' %s ',
$styles,$iconlink,$id,$icon,$sty3d,$class,$uqid,$title);

How to add target=_blank automatically to PDF links using PHP?

I'm wondering is it possible to automatically add target=_blank to any PDF link I have on my website, so that it will convert
link text
link text
to
link text
link text
as this site has a lot of PDFs, and it would be easier to do this automatically rather than have to set them all one-by-one.
I have tried the Javascript solution:
$(".newWindow a[href$='pdf']").attr('target','_blank');
But am wondering is there a way to do this automatically in PHP, perhaps by adding something to Wordpress's functions file?
If your .pdf links are only in your pages content. The fastest and easiest way to to do it is to replace inside your theme template file that shows your page content the following:
the_content();
by
echo str_replace('.pdf"', '.pdf" target="_blank"', get_the_content());
This will be inside the file content.phpof your theme.
Note that the function quoted above may have a parameter, (for example the_content('',FALSE,'');) you need to pass the same parameter in the get_the_content()function as well.
Using regex, you can perform smarter replacements. This example below will work on all <a> tags with a PDF extension in the URL, even if the URL has parameters.
echo preg_replace('/((<a (?=.*\.pdf)(?!.*target="_blank").*?)>)/', '$2 target="_blank">', get_the_content());
This regex performs two lookaheads: first, to check if the URL contains a PDF extension; and second, to check if the target="_blank" attribute is not already set. If both of those requirements are satisfied, then it will append the target="_blank" attribute to the end of the tag.

Wordpress automatically adding site url to href, though href not empty

So I'm trying to debug a somewhat confusing problem. I'm using a Wordpress plugin for a Topspin store that uses colorbox to popup a window to display more information about an item. Here's the site: okgo.net/store. In the backend code for this page a div block is created containing links that that should look like this:
<a class="topspin-view-item" href="#!/77022">
The php that does that is as follows:
<a class="topspin-view-item" href="#!/<?php echo $item['id']; ?>">
The problem is that what is being spat out at the end is not that. It looks like this:
<a class="topspin-view-item" href="http://okgo.net/video-store/#!/89712">
I've understood from another post on here that the default behavior of Wordpress is to fill empty hrefs (ie href="") with the site url. So my guess is that Wordpress is for some reason interpreting this as an empty href? Except that that doesn't seem quite right either.
I've played around with this a bit. One thing that happens is that if I remove the has from the above PHP the siteurl is not output at all. That of course breaks my code.
Any ideas? Any help would be warmly appreciated.
The way we ended up fixing this for those who may be interested is by simply adding the following line of code to the jQuery handler that dealt with the on submit event:
event.preventDefault()
Perhaps this will be of help to someone...

Resources