Retrieving post excerpt as a shortcode
Just add this to your child theme’s functions.php file: add_shortcode( ‘output_post_excerpt’, ‘get_the_excerpt’ ); Then use [output_post_excerpt]
Just add this to your child theme’s functions.php file: add_shortcode( ‘output_post_excerpt’, ‘get_the_excerpt’ ); Then use [output_post_excerpt]
get_template_part doesn’t return its value, it outputs it, which is how it would normally be used. Think of it this way, how would it know wether to echo the template or return it? So instead, we use output buffers to catch the output and flush it to a variable, e.g.: ob_start( ); echo “test”; $output … Read more
It’s because you have forgot to use $atts[‘post_id’] please find below code. function acf_featured_item_shortcode( $atts ) { // Attributes $atts = shortcode_atts( array( ‘post_id’ => ”, ), $atts ); $post_id = $atts[‘post_id’]; $image = get_field(‘featured_item’, $post_id ); $size=”medium”; // (thumbnail, medium, large, full or custom size) if( $image ) { $output = wp_get_attachment_image( $image, $size, … Read more
It’s because if the user enters large=”true”, then $atts[‘small’] isn’t defined. The normal solution is to use shortcode_atts() to set default values for the parameters, but you’re not putting the result of shortcode_atts() into $atts, you’re just just extracting it. This means that $small will be defined, but $atts[‘small’] won’t be. The proper way to … Read more
No, by the time your shortcode runs, the header has already been sent over the network, even the post title. It is too late to change things already sent, aka everything before it reached the_content. There is 1 way to “do it” sort of, but it carries a very, very high cost, and won’t be … Read more
$_GET is a glob var. which is triger/created when you’re sending html form data og visit a link. When is send from form you can add the needet info in “action” atr. But from youre example i see onlu that you return from the function some string…did not see the part of adding it to … Read more
You have a typo in your code (enwhile instead of endwhile) so PHP is complaining because of non-closed while loop. Correct it and everything should be ok.
You need to use the equivalent functions that return their value. Those are get_the_permalink() and get_the_title(). Most WordPress template functions that begin with the_ and echo their values have equivalent functions that return their values that begin with get_the_,
the_post_thumbnail() echos the thumbnail and returns nothing. You probably want to use get_the_post_thumbnail() which returns it as a string. Your code currently is equivalent to this: if (has_post_thumbnail()) { // Echo the thumbnail the_post_thumbnail(); // Apply the filter but do nothing with the result. apply_filters( ‘the_content’, “[frame_left]”.”[/frame_left]”); } if (has_post_thumbnail()) { // Echo the thumbnail … Read more
Here you go: add_shortcode(‘latest_tweets’, ‘latest_tweets’); function latest_tweets($atts){ extract(shortcode_atts(array( ‘max’ => 5 ), $atts)); $twitter_id = esc_attr(strip_tags($atts[0])); // try to get data from cache to avoid slow page loading or twitter blocking if (false === ($output = get_transient(“latest_tweets_{$twitter_id}”))): $doc = new DOMDocument(); $feed = “http://twitter.com/statuses/user_timeline/{$twitter_id}.rss”; $doc->load($feed); $output = “<ul>”; $i = 1; foreach ($doc->getElementsByTagName(‘item’) as $node) … Read more