Why is overwriting $GLOBALS killing the_content()?

Template tags like the_content() and the_title() are dependent on the global $post variable ($GLOBALS[‘post’]). See the source code for get_post(), which get_the_title(), for example, uses to get the current post so it can get its title: function get_post( $post = null, $output = OBJECT, $filter=”raw” ) { if ( empty( $post ) && isset( $GLOBALS[‘post’] … Read more

Alter existing page contents based on url

I belive this will work for you: Create a “page” called “stuff”, then create another page called “foo”, make it child of “stuff”, now stuff/foo will exist and won’t be 404. Finally use the_content filter and make the required data manipulation. The other choice (hard way) you’d have is to use pre_get_post hook, so you … Read more

Changing the argument of a function

Try: (add to functions.php of your theme) add_filter( ‘woocommerce_breadcrumb_defaults’, ‘wpse_woocommerce_breadcrumb_defaults’ ); function wpse_woocommerce_breadcrumb_defaults( $args ) { $args[‘wrap_before’] = ‘<nav class=”woocommerce-breadcrumb my-class”>’; $args[‘wrap_after’] = ‘</nav>’; return $args; } Or, copy: wp-content/plugins/woocommerce/templates/global/breadcrumb.php to wp-content/themes/your-theme/templates/global/breadcrumb.php UPDATE: This is the correct path and not above: (thanks @mmm) wp-content/themes/your-theme/woocommerce/global/breadcrumb.php and change the echo $wrap_before; and echo $wrap_after; to your liking.. … Read more

How can I filter tag_description()?

The filter is well hidden, but you can track it down from tag_description ($tag), which calls term_description ($term=$tag, $taxonomy = ‘post_tag’), which in turn calls get_term_field (‘description’, $tag, ‘post_tag’). And finally you get the call sanitize_term_field (‘description’, $tag->$description, $tag->tag_id, $tag->post_tag, ‘display’). Once you’re in sanitize_term_field you see a whole lot of filters. It looks like … Read more

How to trim white space in search terms?

I came across the same problem. In my opinion, this should be the default search behavior in WP. The solution is to filter the array of parsed query variables. See the documentation here. Add this to the functions.php file in your theme directory. add_filter(‘request’, function ($query_vars) { if (!is_admin() && !empty($query_vars[‘s’])) { $query_vars[‘s’] = trim($query_vars[‘s’]); … Read more

Add something after a filter

that’s exactly what the filter is here for! apply_filters is a hook that allows you to modify the array that is passed there as a second argument. Try this: function example_additional_wpneo_menus( $menus ) { // check the type just in case if ( ! is_array( $menus ) ) { return $menus; } $menus[‘myform’] = [ … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)