Simple Spoiler Shortcode

Below, you’ll find a detailed guide on how to add the Simple Spoiler 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 Simple Spoiler Plugin shortcode not to show or not to work correctly.

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

Plugin Icon
Simple Spoiler

"Simple Spoiler is a unique WordPress plugin that allows you to easily create and manage spoilers on your site, enhancing user engagement and site navigation."

★★★★✩ (6) Active Installs: 3000+ Tested with: 6.0.6 PHP Version: 5.6
Included Shortcodes:
  • [spoiler]

Simple Spoiler [spoiler] Shortcode

The Simple-Spoiler shortcode allows users to create a collapsible content area. It checks if a title is set, and if not, defaults to ‘Spoiler’.

Shortcode: [spoiler]

Parameters

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

  • title – customizes the title of the spoiler section

Examples and Usage

Basic example – Spoiler shortcode without a title attribute

[spoiler]Hidden content goes here[/spoiler]

This shortcode will create a spoiler box with the default title, ‘Spoiler’. The content within the shortcode tags will be hidden until the user clicks on the spoiler box.

Advanced examples

Adding a title to the spoiler shortcode

[spoiler title="Custom Title"]Hidden content goes here[/spoiler]

In this example, the spoiler box will have a custom title ‘Custom Title’ instead of the default ‘Spoiler’. The content within the shortcode tags remains hidden until clicked.

Using the spoiler shortcode with HTML content

[spoiler title="Custom Title"]

This is a paragraph of hidden content.

  • Hidden list item
[/spoiler]

This example demonstrates how you can use HTML tags within the spoiler shortcode to format the hidden content. In this case, the hidden content includes a paragraph and a list item.

PHP Function Code

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

Shortcode line:

add_shortcode( 'spoiler', 'simple_spoiler_shortcode' );

Shortcode PHP function:

                    function simple_spoiler_shortcode($atts, $content) {
	if ( ! isset($atts['title']) ) {
		$sp_name = __( 'Spoiler', 'simple-spoiler' );
	} else {
		$sp_name = $atts['title'];
	}
	return '<div class="spoiler-wrap">
				<div class="spoiler-head folded">'.$sp_name.'</div>
				<div class="spoiler-body">'.$content.'</div>
			</div>';
}
                    

Code file location:

simple-spoiler/simple-spoiler/simple-spoiler.php

Conclusion

Now that you’ve learned how to embed the Simple Spoiler 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.

Comments

Leave a Reply

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