Beda Schmid

Document Change registered Taxonomies labels

add_filter( ‘init’, ‘custom_registered_taxonomy_admin_labels’ ); function custom_registered_taxonomy_admin_labels() { global $wp_taxonomies; $labels = &$wp_taxonomies[‘your_taxonomy’]->labels;//change to your taxonomy slug $labels->name = ‘NA …

Document Conditionally enqueue a Script or Style

add_action( ‘wp_enqueue_scripts’, ‘conditionally_enqueue_styles’); function conditionally_enqueue_styles() { if ( is_front_page() || !is_archive() ) { wp_enqueue_style(‘bootstrap’, ‘https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css’ …

Document Remove a Post Type from the Search Results

add_action( ‘pre_get_posts’, ‘remove_post_type_from_front_end_search_results’); function remove_post_type_from_front_end_search_results($query){ if(is_admin() || !$query->is_main_query()) return; if($query->is_search()){ $post_type_to_remove = ‘y …

Document Change the WP Search URL

add_action( ‘template_redirect’, ‘change_wp_search_url’ ); function change_wp_search_url() { if ( !empty( $_GET[‘s’] ) ) { wp_redirect( home_url( “/your_page/?your_param=” ) . urlencode( get_query_var( ‘s’ ) ) ); exit(); } }

Document Make Registered Flat taxonomies Hierarchical (example for Tags)

add_action(‘init’, ‘make_registered_flat_taxonomies_hierarchical’); function make_registered_flat_taxonomies_hierarchical() { // Maintain the built-in rewrite functionality of WordPress tags global $wp_rewrite; $rewrite = array( ‘hierarchical’ => fa …

Document Remove WP Admin Access for any role

With this filter you can remove access – both visually and programmatically – to the WP Admin for any role defined. Usually you’d install a whole plugin for this feature but in fact it doesn’t need a plugin with lots of overhead. This code also conside …

Document ShortCode to display count of related posts

A general purpose shortcode to display the number of posts related to the current post in a specified relationship. /** * Register connections shortcode * * @att (string) relationship : post relationship slug * @return count of connected posts */ add_s …

Document WPML LS on specific Post Types only

This code will prevent rendering the language switcher if the current post type is not a “post” or a “product”.   Of course, you can customize it based on your needs. The code – as usual for filters – goes to the functions.php file. function remov …

Document Make iFrames Multilingual

By default iFrames are not multilingual because they are HTML code. but there’s a way to easily make them multilingual without too much hassle. function my_embed( $atts ) { $a = shortcode_atts( array( ‘src’ => ‘default_url_goes_here’, ), $atts ); $a …