Add To All Shortcodes

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

Before starting, here is an overview of the Add To All Plugin and the shortcodes it provides:

Plugin Icon
WebberZone Snippetz – Header, Body and Footer manager

"WebberZone Snippetz is a comprehensive manager for your WordPress website's header, body, and footer. It simplifies customization and ensures a seamless user experience."

★★★★☆ (10) Active Installs: 3000+ Tested with: 6.3.2 PHP Version: 7.3
Included Shortcodes:
  • [ata_reading_time]
  • [ata_snippet]

Add To All [ata_reading_time] Shortcode

The ‘Add-to-All’ plugin shortcode ‘ata_reading_time’ calculates the reading time of a post. It uses the average reading speed of 200 words per minute as a standard. This shortcode generates a span element with the class ‘ata_reading_time’ and the reading time of the post. It can be customized with ‘before’ and ‘after’ attributes.

Shortcode: [ata_reading_time]

Parameters

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

  • post – It refers to the current post object.
  • wpm – It defines words per minute for reading time calculation.
  • before – Text to display before the reading time.
  • after – Text to display after the reading time.

Examples and Usage

Basic example – Displaying the reading time of a post using the default Words Per Minute (WPM) setting of 200.

[ata_reading_time post="123" /]

Advanced examples

Modifying the Words Per Minute (WPM) setting to 250, which adjusts the reading time calculation accordingly.

[ata_reading_time post="123" wpm="250" /]

Adding a prefix and suffix to the reading time display. The ‘before’ and ‘after’ attributes allow you to add custom text before and after the reading time.

[ata_reading_time post="123" before="Reading Time: " after=" minutes" /]

Displaying the reading time of a post with a specific content. This overrides the content of the post with the specified text, and calculates the reading time based on it.

[ata_reading_time post="123" content="This is a custom content for the reading time calculation." /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'ata_reading_time', array( $this, 'reading_time' ) );

Shortcode PHP function:

                    function reading_time( $atts, $content = null ) {

		$atts = shortcode_atts(
			array(
				'post'   => get_post(),
				'wpm'    => 200,
				'before' => '',
				'after'  => '',
			),
			$atts,
			'ata_reading_time'
		);

		$post = get_post( $atts['post'] );
		if ( ! $post ) {
			return '';
		}

		if ( empty( $content ) ) {
			$content = get_post_field( 'post_content', $post );
		}

		$output  = sprintf( '<span class="ata_reading_time ata_reading_time_%s">', $post->ID );
		$output .= \WebberZone\Snippetz\Util\Helpers::get_reading_time( $content, $atts );
		$output .= '</span>';

		return $output;
	}
                    

Code file location:

add-to-all/add-to-all/includes/frontend/class-shortcodes.php

Add To All [ata_snippet] Shortcode

The Add-to-All plugin shortcode, ‘ata_snippet’, allows for the embedding of custom code snippets within posts. It normalizes attribute keys to lowercase and sets a default ‘id’ value. The id is then used to retrieve the corresponding snippet. The snippet content is wrapped within a div, allowing for unique styling.

Shortcode: [ata_snippet]

Parameters

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

  • id – Defines the specific snippet to display by its unique number

Examples and Usage

Basic example – Utilizing the shortcode to display a specific snippet by referencing its ID.

[ata_snippet id=5 /]

Advanced examples

Using the shortcode to display a snippet by referencing its ID. If the snippet is not found by ID, it will return an empty string.

[ata_snippet id=10 /]

Another example of the shortcode usage. If the snippet ID is not specified or the ID is not found, it will return an empty string. If the snippet is found, it will be wrapped in a div with a class based on its ID.

[ata_snippet id=15 /]

Please note that the shortcode [ata_snippet /] without any ID will also return an empty string, as no specific snippet is being referenced.

PHP Function Code

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

Shortcode line:

add_shortcode( 'ata_snippet', array( $this, 'snippet' ) );

Shortcode PHP function:

                    function snippet( $atts ) {

		// Normalize attribute keys, lowercase.
		$atts = array_change_key_case( (array) $atts, CASE_LOWER );

		$atts = shortcode_atts(
			array(
				'id' => 0,
			),
			$atts,
			'ata_snippet'
		);

		$id      = absint( $atts['id'] );
		$snippet = Functions::get_snippet( $id );

		$content = is_object( $snippet ) ? $snippet->post_content : $snippet;

		$output  = sprintf( '<div class="ata_snippet ata_snippet_%s">', $id );
		$output .= do_shortcode( $content );
		$output .= '</div>';

		return $output;
	}
                    

Code file location:

add-to-all/add-to-all/includes/snippets/class-shortcodes.php

Conclusion

Now that you’ve learned how to embed the Add To All 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 *