Shortcode to Gutenberg-block: additional text on front-end and conditional display

Although a little different than I had initially anticipated, I have found/created a solution to my two problems. Conditionals I have opted to move non-required input to the sidebar, using the InspectorControls-element. Reason for this is that I realised that it would be impossible to hide a field (in the editor-part of the screen) that … Read more

meta content on required pages

After too many tries i have found following solution myself, but this could save others time. $pid = (isset($_GET[‘post’]) ? $_GET[‘post’] : $_POST[‘post_ID’]); $page_att = get_page( $pid ); $page_parent = $page_att->post_parent; if(15 == $page_parent){ //register metabox }

Add default content to posts in a specific category?

Using the code you posted, the selected category’s ID is available in the $_REQUEST, you can check that ID against your products category in the default_content filter and add content if there’s a match: add_filter( ‘default_content’, ‘wpa70073_default_products_content’ ); function wpa70073_default_products_content( $content ) { // change this to your desired category ID $products_category_id = 42; if( … Read more

Exclude custom function content from certain pages

Check for the type of the page: function get_author_bio ($content=””){ if ( ! is_single() ) // not a blog post, stop immediately { return $content; } global $post; // continue with regular work The easiest way to learn these check functions is a look at the function get_body_class(). Here are the most important: is_rtl() is_front_page() … Read more

how to test for attached image

function has_image_attachment($post_id) { $args = array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image/jpeg’, ‘numberposts’ => -1, ‘post_status’ => null, ‘post_parent’ => $post_id ); $attachments = get_posts($args); if(is_array($attachments) && count($attachments) > 0) { //Has image attachments return true; } else { return false; } }

Can shortcodes contain conditional statements? Even without them my shortcode renders blank page

your conditional breaks the concatenation of the strings (which is not in your code, anyway) try to re-write this section: function info($atts, $content = null) { extract(shortcode_atts(array( “name” => ”, “image” => ”, “address” => ”, “phone” => ”, “email” => ”, “website” => ”, “description” => ”, “amenities” => ” ), $atts)); $output=”<span class=”sort”>”; … Read more