Easy Accordion Free Shortcode

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

Before starting, here is an overview of the Easy Accordion Free Plugin and the shortcodes it provides:

Plugin Icon
Easy Accordion – Best Accordion FAQ Plugin for WordPress

"Easy Accordion – Best Accordion FAQ Plugin for WordPress is a user-friendly tool that assists in creating responsive FAQ sections. Its straightforward, free-to-use design is perfect for beginners."

★★★★☆ (239) Active Installs: 50000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [sp_easyaccordion]

Easy Accordion Free [sp_easyaccordion] Shortcode

The Easy Accordion Free plugin shortcode is designed to create a dynamic accordion display. It verifies the post type and status, then fetches data from post meta and options. It enqueues necessary CSS files and loads dynamic styles. If the shortcode ID isn’t found, it updates the options. Lastly, it generates the HTML for the accordion and returns it.

Shortcode: [sp_easyaccordion]

Parameters

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

  • id – Unique identifier for the specific accordion content

Examples and Usage

Basic example – A simple use case of the shortcode to display an accordion by referencing its ID.

[sp_easyaccordion id=1 /]

Advanced examples

Using the shortcode to display an accordion by referencing both ID and providing additional content. If the accordion with the given ID is found, it will be displayed with the provided content.

[sp_easyaccordion id=1]Your additional content goes here...[/sp_easyaccordion]

Using the shortcode to display multiple accordions by referencing their IDs. This can be useful when you want to display multiple accordions within the same section of your website.

[sp_easyaccordion id=1 /]
[sp_easyaccordion id=2 /]
[sp_easyaccordion id=3 /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'sp_easyaccordion', array( $this, 'sp_easy_accordion_shortcode' ) );

Shortcode PHP function:

function sp_easy_accordion_shortcode( $attributes, $content = null ) {
		if ( empty( $attributes['id'] ) || ( get_post_status( $attributes['id'] ) === 'trash' ) || 'sp_easy_accordion' !== get_post_type( $attributes['id'] ) ) {
			return;
		}

		$post_id = esc_attr( intval( $attributes['id'] ) );

		// Content Accordion.
		$upload_data        = get_post_meta( $post_id, 'sp_eap_upload_options', true );
		$shortcode_data     = get_post_meta( $post_id, 'sp_eap_shortcode_options', true );
		$settings           = get_option( 'sp_eap_settings' );
		$main_section_title = get_the_title( $post_id );
		ob_start();
		// Stylesheet loading problem solving here. Shortcode id to push page id option for getting how many shortcode in the page.
		$get_page_data      = SP_EA_Front_Scripts::get_page_data();
		$found_generator_id = $get_page_data['generator_id'];
		if ( ! is_array( $found_generator_id ) || ! $found_generator_id || ! in_array( $post_id, $found_generator_id ) ) {
			// CSS Files.
			wp_enqueue_style( 'sp-ea-font-awesome' );
			wp_enqueue_style( 'sp-ea-style' );
			$ea_dynamic_css = SP_EA_Front_Scripts::load_dynamic_style( $post_id, $shortcode_data );
			echo '<style>' . $ea_dynamic_css['dynamic_css'] . '</style>';
		}
		// Update options if the existing shortcode id option not found.
		SP_EA_Front_Scripts::easy_accordion_update_options( $post_id, $get_page_data );
		self::sp_eap_html_show( $post_id, $upload_data, $shortcode_data, $main_section_title );
		return ob_get_clean();
	}

Code file location:

easy-accordion-free/easy-accordion-free/public/views/class-easy-accordion-free-shortcode.php

Conclusion

Now that you’ve learned how to embed the Easy Accordion Free 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 *