wp_dropdown_categories and custom attribute

The only filter available is wp_dropdown_cats, which allows you to filter the entire HTML select string and that means trying to string-match markup. That is always a bit questionable. Still… function dropdown_data_attr_wpse_213033($output){ return str_replace(‘<select’,'<select data-live-search=”true”‘,$output); } add_filter(‘wp_dropdown_cats’,’dropdown_data_attr_wpse_213033′); wp_dropdown_categories(); // test

function to erase swear words

Basic Filtering This is just a simple example and would work if you’re just using it for editors that might slip up here or there and put in a swear word by accident. However, if you have to worry about people trying to “spoof” their words for example “focker, fuker, etc” then you’ll probably need … Read more

Set quantity of woocommerce product on page visit [closed]

There was an error in my code. From here: http://www.sitepoint.com/woocommerce-actions-and-filters-manipulate-cart/ Changing // correct quantity unset( $woocommerce->cart->cart_contents[$product_id] ); $woocommerce->cart->add_to_cart( $product_id, $quantity ); To // correct quantity // Get it’s unique ID within the Cart $prod_unique_id = $woocommerce->cart->generate_cart_id( $product_id ); // Remove it from the cart by un-setting it unset( $woocommerce->cart->cart_contents[$prod_unique_id] ); $woocommerce->cart->add_to_cart( $product_id, $quantity ); Has … Read more

Change size and crop medium_large images

You can call add_image_size() again to update the existing image size. Assuming it is called medium_large (Events Manager Pro is a paid plugin so not very much people have it) you can do something like: <?php function update_medium_large_size_wpse216595() { add_image_size( ‘medium_large’, 600, 255, array( ‘center’, ‘top’ ) ); } add_action( ‘init’, ‘update_medium_large_size_wpse216595’, 11 ); Then … Read more

Two functions.php files in one theme

The functions.php is convention for a file that will be automatically loaded by WordPress. From there it is a normal PHP mechanics. You can further include any other PHP files in it. In some themes it is the only thing that a “root” functions.php does.

Create single.php for specific tag by tag id or name

has_tag() is a function that will check if a post has a certain tag You could integrate it into your code like so: function my_category_templates($single_template) { global $post; if ( in_category( ‘raspee’ )) { $single_template = dirname( __FILE__ ) . ‘/single-raspee.php’; } if ( has_tag( ‘everyone’ )) { $single_template = dirname( __FILE__ ) . ‘/single-everyone.php’; … Read more

Which action hook to use for function?

You don’t need an action, but a filter, because you want to do something with the result of a function. The filter is, predictably, called category_description In this way (didn’t test it though): function wpse236947_trim_category_desc ( $desc, $cat_id ) { // do your thing return $desc; } add_filter( ‘category_description’, ‘wpse236947_trim_category_desc’ );

How to create function from code?

You need to pass it at least 2 parameters, or it won’t know what to look for: <?php function custom_pagination($cat_id, $catnum) { // Start of Pagination $total_childs_query = get_categories( array( ‘parent’ => $cat_id, ‘hide_empty’ => ‘0’ )); $total_terms = count( $total_childs_query ); $pages = ceil($total_terms/$catnum); $base_url = get_term_link( $cat_id, get_query_var( ‘taxonomy’ ) ); // if … Read more

Batch update menu_order attribute alphabetically

Hopefully this helps someone else Dont forget to change “your_post_parent_id_here” with the parent id of your choosing. global $wpdb; $wpdb->query( ‘SELECT @i:=-1’ ); $result = $wpdb->query( ” UPDATE wp_posts SET menu_order = ( @i:= @i+1 ) WHERE post_parent=”your_post_parent_id_here” ORDER BY post_title; ” );