Custom shortcode is causing a WSOD

extract( shortcode_atts( ‘post_type’ => ‘publications_test’, ‘post_status’ => ‘publish’ ‘id’ => ”, ); The above is wrong. You have an array inside that function but it’s not in an actual array. Try this instead: extract( shortcode_atts(array( ‘post_type’ => ‘publications_test’, ‘post_status’ => ‘publish’, ‘id’ => ”, ), $atts, ‘testshortcode’); shortcode atts

Shortcode is not returned correctly

You should not echo any content in your shortcode. the_weekday() function echos the date. You can use output buffering or directly get the date: Output buffering: function custom_shortcode() { ob_start(); the_weekday(); $week = ob_get_contents(); ob_end_clean(); return ‘<img src=”https://wordpress.stackexchange.com/wp-content/themes/coworker/images/daily-social-image-” . $week . ‘.gif” width=”100%” />’; } add_shortcode( ‘weekday’, ‘custom_shortcode’ ); Or use the global $wp_locale to … Read more

How to get a post’s details by shortcode?

All you need to do is to write a shortcode add wrap a function around it: function get_post_details($atts) { // Get the shortcode’s attributes $atts = shortcode_atts( array( ‘post’ => 0, ), $atts, ‘get-post-details’ ); // Fetch the ID from $atts array $id = $atts[‘post’]; // Stop the shortcode if no ID is set if … Read more

Shortcode parse error – wrong syntax

UPDATE Seems like the shortcode you’re trying to use is not well coded. If they use it somewhere in the templates alone like echo do_shortcode(‘[share]’); it doesn’t really matter since the ‘[share]’ is the only content passed to do_shortcode(). In your case you’re trying to reuse the shortcode in a context where it’s placed among … Read more

Shortcode syntax errors

You’re missing semicolons after </li>, </ul>, and $output. You also shouldn’t be echoing inside string concatenation and not adding the <li> tag to $output. The below is your code with these fixes. function allphotos_shortcode(){ $images = get_field(‘fl_gallery’); if( $images ) { $output .= ‘<ul>’; foreach( $images as $image ) : $output .= ‘<li><a href=”‘ . … Read more

using do_shortcode

Folowing on Milo’s comment, do_shortcode expects the parameter to be exactly as if it is a shortcode inserted as part of the content, therefor your attempt to quote avatar_upload is just wrong and it should be do_shortcode(‘[avatar_upload]’); In addition it is probably better to just avoid using do_shortcode and call the relevant official API, if … Read more