$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Creating a shortcode in a plugin that includes JS|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Creating a shortcode in a plugin that includes JS

matteradmin8PV0评论

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
Add a comment  | 

1 Answer 1

Reset to default 2

Hook 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.

Post a comment

comment list (0)

  1. No comments so far