javascript - Embedding Tradingview widget in wordpress page -
i extremely beginner of wordpress. need add tradingview widget on wordpress page. code below.
<!-- tradingview widget begin --> <span id="tradingview-copyright"><a ref="nofollow noopener" target="_blank" href="http://www.tradingview.com" style="color: rgb(173, 174, 176); font-family: "trebuchet ms",tahoma,arial,sans-serif; font-size: 13px;">forex heat map <span style="color: #3bb3e4">tradingview</span></a></span> <script src="https://s3.tradingview.com/external-embedding/embed-widget-forex-heat-map.js">{ "currencies": [ "eur", "usd", "jpy", "gbp", "inr" ], "width": "450", "height": "500", "locale": "en" }</script> <!-- tradingview widget end -->
the script part suppressed wordpress. please let me know if can directly add widgets on wordpress page. if hooking in function.php if done sample code useful. given code works fine in plain html.
if want insert script page, use plugin or set custom field in acf, easiest way create shortcode can add post editor.
create function in functions.php display script, , use add_shortcode
define shortcode use. e.g.:
/* function displays script */ function insert_tradingview_heatmap_shortcode() { ?> <!-- tradingview widget begin --> <span id="tradingview-copyright"><a ref="nofollow noopener" target="_blank" href="http://www.tradingview.com" style="color: rgb(173, 174, 176); font-family: "trebuchet ms",tahoma,arial,sans-serif; font-size: 13px;">forex heat map <span style="color: #3bb3e4">tradingview</span></a></span> <script src="https://s3.tradingview.com/external-embedding/embed-widget-forex-heat-map.js">{ "currencies": [ "eur", "usd", "jpy", "gbp", "inr" ], "width": "450", "height": "500", "locale": "en" }</script> <!-- tradingview widget end --> <?php } /* create shortcode called tradingview_heatmap run function */ add_shortcode('tradingview_heatmap', 'insert_tradingview_heatmap_shortcode');
then display heat map in post/page, need put following shortcode post editor:
[tradingview_heatmap]
update:
it might simple shortcode work first, can rule out it.
add functions.php:
/* function display test message */ function my_test_shortcode() { ?> <p>this added test shortcode!</p> <?php } add_shortcode('my_test_shortcode', 'my_test_shortcode');
type following post editor new, empty post, save , view post in browser:
[my_test_shortcode]
it should print "this added test shortcode!" post text.
Comments
Post a Comment