Below, you’ll find a detailed guide on how to add the Stock Ticker Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Stock Ticker Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Stock Ticker Plugin and the shortcodes it provides:
"Stock Ticker is a dynamic WordPress plugin that displays real-time stock market information. Its user-friendly interface allows you to customize and track specific stocks directly from your site."
- [stock_ticker]
Stock Ticker [stock_ticker] Shortcode
The Stock Ticker shortcode is a dynamic tool that generates a scrolling or static stock ticker. It displays live stock prices using defined symbols. Attributes like ‘symbols’, ‘show’, ‘number_format’, ‘decimals’, ‘speed’, and ‘loading_message’ allow customization of the ticker’s display. It also supports ‘prefill’ and ‘duplicate’ options for ticker content control.
Shortcode: [stock_ticker]
Parameters
Here is a list of all possible stock_ticker shortcode parameters and attributes:
symbols
– defines the stock symbols to be displayed.show
– controls what data to be shown for the stocks.number_format
– sets the number format used in the ticker.decimals
– determines the number of decimal places.static
– when set to 1, the ticker will not be animated.nolink
– when set to 1, the stocks won’t have a hyperlink.prefill
– when set to 1, the ticker will display data before fully loaded.duplicate
– when set to 1, the ticker will repeat the stock symbols.speed
– controls the speed of the ticker animation.class
– allows custom CSS classes to be added to the ticker.loading_message
– sets the message displayed while loading stock data.
Examples and Usage
Basic example – Displaying stock symbols with the default settings.
[stock_ticker symbols="AAPL,GOOG,MSFT" /]
Advanced examples
Displaying stock symbols with a custom loading message and speed.
[stock_ticker symbols="AAPL,GOOG,MSFT" loading_message="Fetching stock data..." speed="70" /]
Displaying stock symbols with a custom number format and decimal places.
[stock_ticker symbols="AAPL,GOOG,MSFT" number_format="dc" decimals="4" /]
Displaying stock symbols with a custom class and static display.
[stock_ticker symbols="AAPL,GOOG,MSFT" class="my-custom-class" static="1" /]
Displaying stock symbols without links and with prefill option.
[stock_ticker symbols="AAPL,GOOG,MSFT" nolink="1" prefill="1" /]
Displaying stock symbols with duplicate option and custom speed.
[stock_ticker symbols="AAPL,GOOG,MSFT" duplicate="1" speed="60" /]
PHP Function Code
In case you have difficulties debugging what causing issues with [stock_ticker]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'stock_ticker', array( $this, 'shortcode' ) );
Shortcode PHP function:
function shortcode( $atts ) {
$defaults = $this->defaults;
$atts = shortcode_atts(
array(
'symbols' => $defaults['symbols'],
'show' => $defaults['show'],
'number_format' => isset( $defaults['number_format'] ) ? $defaults['number_format'] : 'dc', // dot comma
'decimals' => isset( $defaults['decimals'] ) ? $defaults['decimals'] : 2,
'static' => 0,
'nolink' => 0,
'prefill' => 0,
'duplicate' => 0,
'speed' => isset( $defaults['speed'] ) ? $defaults['speed'] : 50,
'class' => '',
'loading_message' => isset( $defaults['loading_message'] ) ? $defaults['loading_message'] : __( 'Loading stock data...', 'wpaust' ),
),
$atts
);
// If we have defined symbols, enqueue script and print stock holder
if ( ! empty( $atts['symbols'] ) ) {
// Strip tags as we allow only real symbols
$atts['symbols'] = strip_tags( $atts['symbols'] );
// Enqueue script parser on demand
if ( empty( $defaults['globalassets'] ) ) {
wp_enqueue_script( 'stock-ticker' );
if ( ! empty( $defaults['reload'] ) ) {
wp_enqueue_script( 'stock-ticker-reload' );
}
}
// startEmpty based on prefill option
$empty = empty( $atts['prefill'] ) ? 'true' : 'false';
// duplicate
$duplicate = empty( $atts['duplicate'] ) ? 'false' : 'true';
// Return stock holder
return sprintf(
'<div
class="stock-ticker-wrapper %5$s"
data-stockticker_symbols="%1$s"
data-stockticker_show="%2$s"
data-stockticker_number_format="%4$s"
data-stockticker_decimals="%10$s"
data-stockticker_static="%3$s"
data-stockticker_class="%5$s"
data-stockticker_speed="%6$s"
data-stockticker_empty="%7$s"
data-stockticker_duplicate="%8$s"
><ul class="stock_ticker"><li class="init"><span class="sqitem">%9$s</span></li></ul></div>',
$atts['symbols'], // 1
$atts['show'], // 2
$atts['static'], // 3
$atts['number_format'], // 4
$atts['class'], // 5
$atts['speed'], // 6
$empty, // 7
$duplicate, // 8
$atts['loading_message'], // 9
$atts['decimals'] // 10
);
}
return false;
}
Code file location:
stock-ticker/stock-ticker/stock-ticker.php
Conclusion
Now that you’ve learned how to embed the Stock Ticker Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply