Preparing accordion content

We already identified the importance of shortcodes for adding UI elements to posts or pages. Therefore, we will be using another shortcode to prepare the content for the accordion. Let's add the following code to the implementation of the accordion shortcode:

add_shortcode( 'wqkm_accordian', array( $this, 'display_accordian') ); public function display_accordian( $atts, $content ){ $sh_attr = shortcode_atts( array( 'id' => '0' ), $atts ); extract($sh_attr); $display = '<div id="accordion">'; if( trim( get_post_meta( $id, '_wqkm_tab_1' , true ) ) != '' ){   $display .= '<h3>'.get_the_title( $id ).'</h3>';   $display .= '<div><p>'.get_post_meta( $id, '_wqkm_tab_1' , true ).' </p> </div>'; } // other fields $display .= ...

Get WordPress Development Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.