Search with filters

Here is one to create a search form with tag and category filters. For filtering posts this form uses the default text input way, where user can type some search phrase that is matched against post titles and content. 1) Added to theme’s functions.php function get_tag_ids_and_names() { $out = array(); $arga = array( // check … Read more

add_action with associative array

You passed the action an associative array, so your hooked function will recieve an associative array. It’s a little clearer if we retype it like this: $associative_array = array( ‘product_id’ => $product_id , ‘outbiddeduser_id’ => $outbiddeduser, ‘log_id’ => $log_id ); do_action( ‘woocommerce_simple_auctions_outbid’, $associative_array ); Thus: add_action(‘woocommerce_simple_auctions_outbid’, ‘test’, 10, 1); function test( $associative_array ) { It … Read more

Add filter return false not working

Instead of adding the filter inside of the add_action(), you need to call the filter directly. You have this in your functions.php file: function filter_after_setup_theme() { add_filter( ‘tc_bridge_for_woocommerce_content_order_table_is_after’, ‘__return_false’ ); } add_action(‘after_setup_theme’, ‘filter_after_setup_theme’); You are telling to WordPress to execute the filter when the action after_setup_theme happens (which is called before init hook, according to … Read more

Remove style tags from head

My solution removes now all <link></link> tags and <style>@import url()</style> googleapi entries in the given HTML: add_action( ‘wp_footer’, ‘SPDSGVOPublic::removeGoogleFonts’ ); /** * Remove all occurrences of google fonts */ public static function removeGoogleFonts() { ob_start(); $content = ob_get_clean(); $patternImportUrl=”/(@import[\s]url\((?:”|\”)((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)(?:”|\’)\)\;)/’; $patternLinkTag = ‘/<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'”])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>/’; preg_match_all($patternImportUrl, $content, $matchesImportUrl); preg_match_all($patternLinkTag, $content, $matchesLinkTag); $matches = array_merge($matchesImportUrl,$matchesLinkTag); foreach( $matches as $match … Read more

Archive Widget – Count only parent posts

I haven’t tested this, but I found a sample that was close. I have modified it to be similar to what you want. I’m not sure it is 100%, but it should get you really close: add_action(‘pre_get_posts’,’wpse_filter_parents_only’); function wpse_filter_parents_only($query){ if (!is_admin() && is_category(’26’)){ $query->set(‘post_parent’,0); } return $query; } This should update what WP_Query retrieves from … Read more

Changing title using filter not working with argument

Maybe you can add a higher priority to your filter as the 3rd parameter of the hook: /** * Modify the data * * @param String $data * * @return String $data */ function change_title( $data ) { global $post; return ‘Page ID ‘ . $data; } add_filter( ‘the_title’, ‘change_title’, 15 ); The default priority … Read more

Unable to defer loading of jquery

add_filter( ‘script_loader_tag’, function ( $tag, $handle ) { $handlesToDefer = array(‘jquery-migrate’, ‘bootstrap’, ‘jquery-core’); if ( !in_array($handle, $handlesToDefer) ) return $tag; return str_replace( ‘ src’, ‘ defer=”defer” src’, $tag );