I use a lot of embedded tweets on my site. The script always gets stripped out. I added Twitter's code to my theme, but it doesn't work with infinite scroll. So I'd like to make a shortcode that will import the needed script from Twitter.
Please take a look at what I've got below. I can't get it to work and I'm not sure what's wrong. Thanks.
<?php
/*
Plugin Name: Tweet Shortcode
Description: Use [tweet] to insert the Twitter embed javascript so it won't be stripped from your post.
Author: Nate Hill
Version: 0.1
*/
add_shortcode( 'tweet', 'tweets' );
function tweet_code( $atts ) {
$tweet_text = <<<'EOD'
<!-- Tweet JS. Do not edit. -->
<script LANGUAGE="JavaScript" TYPE="text/javascript" async src="//platform.twitter/widgets.js" charset="utf-8"></script>
<!-- end Tweet JS tag -->
EOD;
return $tweet_text;
}
I use a lot of embedded tweets on my site. The script always gets stripped out. I added Twitter's code to my theme, but it doesn't work with infinite scroll. So I'd like to make a shortcode that will import the needed script from Twitter.
Please take a look at what I've got below. I can't get it to work and I'm not sure what's wrong. Thanks.
<?php
/*
Plugin Name: Tweet Shortcode
Description: Use [tweet] to insert the Twitter embed javascript so it won't be stripped from your post.
Author: Nate Hill
Version: 0.1
*/
add_shortcode( 'tweet', 'tweets' );
function tweet_code( $atts ) {
$tweet_text = <<<'EOD'
<!-- Tweet JS. Do not edit. -->
<script LANGUAGE="JavaScript" TYPE="text/javascript" async src="//platform.twitter/widgets.js" charset="utf-8"></script>
<!-- end Tweet JS tag -->
EOD;
return $tweet_text;
}
Share
Improve this question
asked Aug 24, 2013 at 6:09
zutto_shonenzutto_shonen
211 silver badge6 bronze badges
2
- 2 Possible duplicate of Enqueue Scripts / Styles when shortcode is present – admcfajn Commented Jan 29, 2019 at 18:35
- except this question was written one year after the "duplicate" you mentioned... – rudtek Commented Feb 8, 2019 at 16:51
1 Answer
Reset to default 2Hook function name should be same. You are using "tweets" function name as a parameter for the add_shortcode() function but actual function name in your code is "tweet_code" so it should be "tweets" as shown in the following code.
<?php
add_shortcode( 'tweet', 'tweets' );
function tweets( $atts ) {
$tweet_text = <<<'EOD'
<!-- Tweet JS. Do not edit. -->
<script LANGUAGE="JavaScript" TYPE="text/javascript" async src="//platform.twitter/widgets.js" charset="utf-8"></script>
<!-- end Tweet JS tag -->
EOD;
return $tweet_text;
}
?>
For more information on add_shortcode function visit this page.