WordPress shortcodes
-
I have created shortcode for posts, now point is i need to shortcode post in post/page which works. Example i embed post2 in post1 and when i visit post1 i see that post2, but when i embed post1 in page1 i dont see post2
This is code i have written so far.
function getPostShortcode( $atts, $content = '' ) { extract( shortcode_atts( array( 'id' => '', 'title' => '' ), $atts, 'post_shortcode' ) ); if ( empty( $atts['id'] ) ) return; $loop = new WP_Query( array( 'post_type' => 'post', 'p' => $atts['id'] ) ); ob_start(); if ( $loop->have_posts() ) { while ( $loop->have_posts() ) : $loop->the_post(); $desc = ! empty( $atts['desc'] ) ? $atts['desc'] : get_the_excerpt(); ?> <div class="post-single-shortcode-aka"> <h2><a href="#"><?php echo $title; ?></a></h2> <p><?php echo $desc; ?></p> </div> <?php endwhile; wp_reset_postdata(); } return ob_get_clean(); } add_shortcode( 'post_shortcode', 'getPostShortcode' );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘WordPress shortcodes’ is closed to new replies.