Only display nav menu if it is populated with menu items?

This solution was shared by @TheDeadMedic over here… $menu_exists_and_has_items = wp_nav_menu( array( ‘theme_location’ => ‘example-menu-location’, ‘container_class’ => ‘example-menu-container’, ‘menu_class’ => ‘example-menu-class’, ‘fallback_cb’ => false, ‘echo’ => false ) ); if ( $menu_exists_and_has_items ) { … Importantly, note that the menu is not echoed in the initial array saved to PHP variable…

how to trash WordPress comments if its not in English

I don’t think it’s a good idea to trash a comment just because it’s in Russian. I’d recommend using Akisment to prevent/stop spam comments instead of deleting them. Prevention is always better than cure. If you still want to delete Russian (non-English) comments, add this code to the functions.php file of your (child) theme. function … Read more

Is there a way to get a path to the theme directory without the server name?

Yes get_template_directory: get_template_directory(): string Retrieves template directory path for the active theme. Returns an absolute server path (eg: /home/user/public_html/wp-content/themes/my_theme), not a URI. In the case a child theme is being used, the absolute path to the parent theme directory will be returned. Use get_stylesheet_directory() to get the absolute path to the child theme directory. To … Read more

FSE Change Post Template to Something Other Than a List

The ul/li tags are hard-coded into the render_block_core_post_template() functíon: $content=””; while ( $query->have_posts() ) { $query->the_post(); $block_content = ( new WP_Block( $block->parsed_block, array( ‘postType’ => get_post_type(), ‘postId’ => get_the_ID(), ) ) )->render( array( ‘dynamic’ => false ) ); $content .= “<li>{$block_content}</li>”; } wp_reset_postdata(); return sprintf( ‘<ul %1$s>%2$s</ul>’, $wrapper_attributes, $content ); See here: https://github.com/WordPress/wordpress-develop/blob/bed9d00fbdac9da08ed13e84186c53a686a1ea78/src/wp-includes/blocks/post-template.php#L69 There would … Read more

Featured Image add tab

WordPress does not have a built-in hook or function on the PHP side that allows you to directly add a new tab to the Media Library Modal window. To achieve this, you need to use JavaScript to modify the media uploader interface. You can add a custom tab to the WordPress Media Library modal by … Read more

How to auto rename JS files to prevent browser cache issues

The function wp_enqueue_script takes a parameter $ver that you can use to automatically add an version parameter to the URL. To always load the newest version of your Javascript-File, you can use the php filemtime-function to give the timestamp of the modification date. In a Plugin, use like this: wp_register_script( ‘my-awesome-script’, plugin_dir_url( __FILE__ ). ‘assets/my-awesome-script.js’, … Read more