Editing

Yes, it is possible. You can use the_content hook and assign your own filter to this hook. Then you should (that is the part when things get a little bit messy) parse and replace content of that post. So for example you can do it like so: function my_the_content_filter($content) { $content = str_replace(‘<h2 ‘, ‘<img … Read more

Reposition Woocommerce Message

WooCommerce renders messages by using woocommerce_show_messages() function. This function is hooked to woocommerce_before_single_product action. So if you don’t want to render messages before single product, you need to remove that hook for the action. remove_action( ‘woocommerce_before_single_product’, ‘woocommerce_show_messages’ ); If you want to render messages in another place, then just call woocommerce_show_messages() function in desired place.

Cast string to number

WP doesn’t “look” at the type of data you have, it just has a default of CHAR. So if you dump your current query you will see respective type cast: CAST(wp_postmeta.meta_value AS CHAR). To make it work you need to specify type argument explicitly ‘type’ => ‘NUMERIC’ and CAST will change accordingly: CAST(wp_postmeta.meta_value AS SIGNED). … Read more

Yoast SEO hooks overriding themselves

Filters should be returned even if your condition fails. You are currently just returning the output when your condition is met, not when it fails. return $string; at the end of each function should solve your issue. EXAMPLE add_filter(‘wpseo_canonical’, ‘listpagecanonical’); function listpagecanonical($string) { if (is_page(1)){ //I do my stuff here return ‘http://canonicalurl.com’ } return $string; … Read more

Replace category titles

Well thank you for this question i did this after you posted this function category_title( $title ){ if( is_category(‘name1’) ){ $title=”name1 title”; }elseif( is_category(‘name2’) ){ $title=”name2 title”; } return $title; } add_filter( ‘get_the_archive_title’, ‘category_title’ ); Hope this helps

How to change posts order on Category and Tag archives?

You can use pre_get_posts action to modify this order. Here’s the code: function my_change_posts_order( $query ){ if ( ! is_admin() && ( is_category() || is_tag() ) && $query->is_main_query() ) { $query->set( ‘order’, ‘ASC’ ); } }; add_action( ‘pre_get_posts’, ‘my_change_posts_order’); What we do here is: We’re adding our function that will modify params for WP_Queries We … Read more

Hook to get image filename when it is uploaded

The handle_upload hook is called after wp_handle_upload is run, and it sends in a named array consisting of ‘file’, ‘url’ & ‘type’. You could possibly use code like this to utilise it, depending on what you need to achieve: function process_images($results) { if( $results[‘type’] === ‘image/jpeg’ ) { // or /png or /tif / /whatever … Read more