Woocommerce checkout field maxlength, make input number field only (postcode)

By the time woocommerce_checkout_fields filter is run, the arrays for billing and shipping have already been created. You can see that here: https://docs.woothemes.com/wc-apidocs/source-class-WC_Checkout.html#101 If you want to effect the default fields, use this hook. function wpse215677_checkout_fields ( $fields ) { $fields[‘postcode’][‘maxlength’] = 4; return $fields; } add_filter(‘woocommerce_default_address_fields’, ‘wpse215677_checkout_fields’); If you want to adjust just the … Read more

How to filter out shortcode when displaying the_excerpt() in the loop?

try this add_filter( ‘get_the_excerpt’, ‘strip_shortcodes’, 20 ); or try this edit echo strip_shortcodes( get_the_excerpt() ); if shortcode is not register with wordpress function add_shortcode add_filter( ‘the_excerpt’, ‘remove_shortcodes_in_excerpt’, 20 ); function remove_shortcodes_in_excerpt( $content){ $content = strip_shortcodes($content); $tagnames = array(‘box’, ‘alert’); // add shortcode tag name [box]content[/box] tagname = box $content = do_shortcodes_in_html_tags( $content, true, $tagnames ); … Read more

How to preserve edits to Name or Slug of term when using wp_update_term on save?

So, thanks to cjbj I finally found the correct answer! I needed to use edited_term instead of edit_term. Very subtle difference. edited_term fires after a term has been saved. // insert stuff into description field of taxonomy function insert_taxonomy_content( $term_id, $tt_id, $taxonomy ){ // only insert content on certain taxonomies if ( $taxonomy === ‘some_custom_taxonomy’ … Read more

Add class or ID to any WordPress function

If you have only one template it’s fine to do something like: echo ‘<p class=”whatever”>’ . get_the_excerpt() . ‘</p>’; However, if you have multiple templates and want to control the classes centrally, you can make a filter on get_the_excerpt as follows (but yeah, that would be in functions.php): add_filter (‘get_the_excerpt’,’wpse240352_filter_excerpt’); function wpse240352_filter_excerpt ($post_excerpt) { $post_excerpt=”<p … Read more

Functions – callback vs fallback

That is not really a question in the focus of WordPress, is also in other programming languages and in our speaking language a topic. Maybe I can clear the difference between these words with a non coding example. Callback A return of a situation to a state. Like a call with the telephone to a … Read more

WP Job Manager Category Drop-down; Change Placeholder Text Via Filter

Based on the testing that I did, the placeholder string Choose a category… cannot be filtered with the submit_job_form_fields filter, but there are still ways to change that string. One way to alter the text is to override the plugin’s default job-filters.php template with your own. Copy the default template, /wp-job-manager/templates/job-filters.php over to your theme: … Read more

Count total number of images in post and echo results as number

Use regex to find all the urls and filter by type. $post = get_post( 504 ); $content = $post->post_content; // match all urls preg_match_all( ‘/(http:|https:)?\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?/’, $content, $matches ); $count = 0; if ( ! empty( $matches ) && ! empty( $matches[ 0 ] ) ) { foreach ( $matches[ 0 ] as $url ) { … Read more