Using this Accordion Plugin, you can show accordion under the post dynamically.
Display dynamically different accordions under the different posts.
First, you must set the custom meta field accordion_id
under your post where you want to display the accordion.
![Display accordion under post dynamically 1 Display accordion under post dynamically 1](https://i.imgur.com/UR38Z22.png)
Then add the following code to your theme function.php file or 3rd party code editor plugin.
add_filter('the_content','accordions_after_content_20200520'); function accordions_after_content_20200520($content){ if(is_singular(array('post'))){ // add your post types here $post_id = get_the_id(); $accordions_id = get_post_meta($post_id,'accordions_id', true); // get accordions id from custom meta field if(!empty($accordions_id)){ $content .= do_shortcode('[accordions id="'.$accordions_id.'"]'); } } return $content; }
![Display accordion under post dynamically 2 Display accordion under post dynamically 2](https://i.imgur.com/yK3WsUS.png)
Once you successfully add your code, the accordion will appear on that post.
![Display accordion under post dynamically 3 Display accordion under post dynamically 3](https://i.imgur.com/OU1rbKN.png)
Display one accordion under all posts.
To display one accordion under all posts, copy the code below and paste it on the function.php file.
add_filter('the_content','accordions_after_content_20200520'); function accordions_after_content_20200520($content){ if(is_singular(array('post'))){ // add your post types here $post_id = get_the_id(); $accordions_id = 3172; // accordions id if(!empty($accordions_id)){ $content .= do_shortcode('[accordions id="'.$accordions_id.'"]'); } } return $content; }
![Display accordion under post dynamically 4 Display accordion under post dynamically 4](https://i.imgur.com/QK4OYuk.png)
Here, replace the value of the accordion_id
with your accordion.
![Display accordion under post dynamically 5 Display accordion under post dynamically 5](https://i.imgur.com/xj1HCm6.png)