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.

Count the number of times the search form template gets included on a page

Just few simple ideas: A) Here’s one suggestion using the get_search_form filter with a static variable to handle the instance counting: add_filter( ‘get_search_form’, function( $form ) { static $instance = 0; $instance++; // Setup your form here with the $instance variable as needed: $form = ‘<form>…</form>’; return $form; } ); B) Another workaround would be … Read more

Copy custom field value to post title

Okay! Finally, I was able to make it work. Below is the complete working code. add_filter( ‘wp_insert_post_data’ , ‘modify_post_title’ , ’99’, 2 ); // Grabs the inserted post data so you can modify it. function modify_post_title( $data ) { if($data[‘post_type’] == ‘artist’ && isset($_POST[‘acf’][‘field_573676a95d920’])) { // If the actual field name of the rating date … Read more

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’ );