custom shortcode in event description
-
I have a custom shortcode I used on my site that outputs the content of a post in another page. That way if you have a page with the same content, you only have to maintain the content in one area.
I want to use the shortcode within the description of my events, however nothing gets outputting on my event page. Is there a way to render my shortcode in the event details section?
This is the shortcode: [my_content id=”261″ /]
The number is the id of the post who’s contens I want to pull in.
This is the code in my functions.php file
function get_post_page_content( $atts) { extract( shortcode_atts( array( 'id' => null, 'title' => false, ), $atts ) ); $the_query = new WP_Query( 'page_id='.$id ); while ( $the_query->have_posts() ) { $the_query->the_post(); if($title == true){ the_title(); } the_content(); } wp_reset_postdata(); } add_shortcode( 'my_content', 'get_post_page_content' );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘custom shortcode in event description’ is closed to new replies.