Ditty Shortcodes

Below, you’ll find a detailed guide on how to add the Ditty Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Ditty Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Ditty Plugin and the shortcodes it provides:

Plugin Icon
Ditty – Responsive News Tickers, Sliders, and Lists

"Ditty – Responsive News Tickers, Sliders, and Lists is a versatile WordPress plugin that empowers you to add dynamic news tickers, sliders, or lists to your website effortlessly. Perfect for showcasing latest updates or highlights."

★★★★☆ (94) Active Installs: 40000+ Tested with: 6.3.2 PHP Version: 7.1
Included Shortcodes:
  • [ditty]
  • [ditty_ticker]
  • [ditty_shortcode_test]
  • [ditty_news_ticker]

Ditty [ditty] Shortcode

The Ditty News Ticker shortcode is a function that helps display news tickers on your WordPress site. This shortcode checks if the user is not an admin and if ‘dittyDev’ is set in the URL parameters. If these conditions are met, it renders the news ticker. If not, it calls the ‘ditty_render’ function to display the ticker.

Shortcode: [ditty]

Examples and Usage

Basic example – Utilizes the ‘ditty’ shortcode to render the ditty news ticker. The ‘id’ attribute is used to specify the specific ditty news ticker to be displayed.

[ditty id=1 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [ditty] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'ditty', [$this, 'do_shortcode'] );

Shortcode PHP function:

function do_shortcode( $atts ) {
		if ( ! is_admin() ) {
      if ( isset( $_GET['dittyDev'] ) ) {
        return $this->render( $atts );
      } else {
        return ditty_render( $atts );
      }
		}
	}

Code file location:

ditty-news-ticker/ditty-news-ticker/includes/class-ditty-render.php

Ditty [ditty_ticker] Shortcode

The Ditty News Ticker shortcode allows for customized display of ticker content. It creates a new instance of Ditty_Display_Type_Ticker, sets default attributes for display and title, and renders the content.

Shortcode: [ditty_ticker]

Parameters

Here is a list of all possible ditty_ticker shortcode parameters and attributes:

  • title – sets the title of the ticker
  • titleDisplay – controls the display of the title
  • titleContentsSize – defines the size of the title
  • titleContentsPosition – sets the position of the title
  • titleElement – determines the HTML element for the title
  • titleElementPosition – sets the position of the title element
  • titleElementVerticalPosition – defines the vertical position of the title element

Examples and Usage

Basic example – Display a simple ticker without a title

[ditty_ticker title=""]

With the above shortcode, a ticker will be displayed without a title. The ‘title’ attribute is set to an empty string, meaning no title will be displayed.

Advanced examples

Display a ticker with a title and customize the title’s display settings

[ditty_ticker title="Breaking News" titleDisplay="block" titleElement="h2" titleElementPosition="end" titleElementVerticalPosition="center"]

In the above example, the ticker will display with the title “Breaking News”. The title will be displayed as a block-level element, with the title text being an h2 element. The title will be positioned at the end of the ticker and vertically centered.

Display a ticker with multiple items

[ditty_ticker]
Item 1
Item 2
Item 3
[/ditty_ticker]

The above example demonstrates how to display a ticker with multiple items. Each item is written on a new line within the shortcode. The ticker will cycle through each item, displaying one at a time.

PHP Function Code

In case you have difficulties debugging what causing issues with [ditty_ticker] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'ditty_ticker', [$this, 'do_ticker_shortcode'] );

Shortcode PHP function:

function do_ticker_shortcode( $atts, $content ) {
    $ticker = new Ditty_Display_Type_Ticker();
    $display_defaults = $ticker->shortcode_atts();
    $title_defaults = [
      'title' => '',
      'titleDisplay' => 'none',
			'titleContentsSize' => 'stretch',
			'titleContentsPosition' => 'start',
			'titleElement' => 'h3',
			'titleElementPosition' => 'start',
			'titleElementVerticalPosition' => 'start',
    ];
    $display_args = shortcode_atts( $display_defaults, $atts );
    $title_args = shortcode_atts( $title_defaults, $atts );
    
    $items = explode( "\n", str_replace( "\r", "", $content ) );
    $items = array_filter( $items, 'trim' );

    if ( ! empty( $items ) ) {
      return $this->render( $items, $display_args, $title_args );
    }
	}

Code file location:

ditty-news-ticker/ditty-news-ticker/includes/class-ditty-shortcodes.php

Ditty [ditty_shortcode_test] Shortcode

The Ditty News Ticker shortcode is a powerful tool that allows users to display a custom message. It uses the ‘test’ attribute to create a paragraph with the specified text.

Shortcode: [ditty_shortcode_test]

Parameters

Here is a list of all possible ditty_shortcode_test shortcode parameters and attributes:

  • test – sets the custom text to be displayed by the shortcode

Examples and Usage

Basic example – Invoke the Ditty News Ticker plugin shortcode without any parameters. This will display the default test message.

[ditty_shortcode_test]

Advanced examples

Pass the ‘test’ attribute to the shortcode. This will replace the default test message with the value provided in the ‘test’ attribute.

[ditty_shortcode_test test="This is a custom test message"]

Include content within the shortcode. The content will be appended to the test message.

[ditty_shortcode_test]Additional content to be displayed[/ditty_shortcode_test]

Combine both the ‘test’ attribute and content within the shortcode. This will display a custom test message followed by the additional content.

[ditty_shortcode_test test="This is a custom test message"]Additional content to be displayed[/ditty_shortcode_test]

PHP Function Code

In case you have difficulties debugging what causing issues with [ditty_shortcode_test] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'ditty_shortcode_test', 'ditty_shortcode_test_display' );

Shortcode PHP function:

function ditty_shortcode_test_display( $atts, $content = '' ) {
	$defaults = [
		'test' => 'test'
	];
	$args = shortcode_atts( $defaults, $atts );

	$html = '';
	$html .= "<p>This is a shortcode test, using the 'test' attribute: <strong>{$args['test']}</strong>.</p>";
	$html .= $content;

	return $html;
}

Code file location:

ditty-news-ticker/ditty-news-ticker/includes/hooks.php

Ditty [ditty_news_ticker] Shortcode

The Ditty News Ticker shortcode allows you to display a customizable news ticker on your site. This shortcode accepts ‘id’ and ‘class’ as parameters, which can be used to specify the ticker’s appearance. It then retrieves the ticker using the ‘get_mtphr_dnt_ticker’ function. The ‘id’ and ‘class’ attributes are sanitized before being passed to the function to ensure secure usage.

Shortcode: [ditty_news_ticker]

Parameters

Here is a list of all possible ditty_news_ticker shortcode parameters and attributes:

  • id – Unique identifier for the specific news ticker
  • class – CSS class name to style the news ticker

Examples and Usage

Basic example – Display a news ticker using its ID

[ditty_news_ticker id=1 /]

Advanced examples

Display a news ticker using its ID and adding a custom CSS class to style it.

[ditty_news_ticker id=2 class="my-custom-class" /]

Display a news ticker using its ID and adding multiple custom CSS classes to style it.

[ditty_news_ticker id=3 class="my-custom-class another-class" /]

Note: Replace ‘my-custom-class’ and ‘another-class’ with your actual CSS classes.

PHP Function Code

In case you have difficulties debugging what causing issues with [ditty_news_ticker] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'ditty_news_ticker', 'ditty_news_ticker_display' );

Shortcode PHP function:

function ditty_news_ticker_display( $atts, $content = null ) {
	$defaults = array(
		'id' => '',
		'class' => ''
	);
	$args = shortcode_atts( $defaults, $atts );

	// Remove the id & class before passing the atts
	unset( $atts['id'] );
	unset( $atts['class'] );
	
	// Return the ticker
	return get_mtphr_dnt_ticker( intval( $args['id'] ), sanitize_html_class( $args['class'] ), $atts );
}

Code file location:

ditty-news-ticker/ditty-news-ticker/legacy/inc/shortcodes.php

Conclusion

Now that you’ve learned how to embed the Ditty Plugin shortcodes, 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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *