Correct way to filter get_pages() function

If you inspect the code for get_pages() you’ll see it calls $wpdb->get_results($query); which in turn calls $this->query( $query ); In there, there’s a filter: $query = apply_filters( ‘query’, $query ); where $query is the full SQL query string, right before it gets executed. Unfortunately, it seems to be the only filter that can do the … Read more

Adding Filter to Homepage only

Even if wrap your filter in a if statement, the function still will be executed. Try this: global $current_class; $current_class=”flex-container”; function rt_oddeven_post_class ( $classes ) { if ( is_home() || is_front_page() ) { global $current_class; $classes[] = $current_class; $current_class = ($current_class == ‘flex-container’) ? ‘flex-container-reverse’ : ‘flex-container’; return $classes; } } add_filter ( ‘post_class’ , … Read more

Filter taxonomy admin pagination

The root problem, as you can see here, resides in the fact that WP counts items (terms) to paginate this way: ‘total_items’ => wp_count_terms( $this->screen->taxonomy, compact( ‘search’ ) ), Instead, it should count terms from the result of the query. I believe this is an issue and that it should be reported on WP bug … Read more

remove action from AMP plugin

Fixed it by changing to add_action( ‘wp_enqueue_scripts’, ‘remove_hooks’ ); function remove_hooks(){ global $wp_query; $postid = $wp_query->post->ID; $format = get_post_format( $postid ); if ($format == ‘gallery’) { remove_action(‘wp_head’, ‘amp_frontend_add_canonical’,10); } }

Filter the regular price of woocommerce products

Unfortunately the filter hook “woocommerce_get_regular_price” is not usable any more. There is another one alternative of that, you can use this below code to achieve your need. function filter_woocommerce_get_regular_price( $price, $product ) { // use $product->get_id() to get product ID // Do any custom logical action return $price; } add_filter( ‘woocommerce_product_get_regular_price’, ‘filter_woocommerce_get_regular_price’, 10, 2 );

Adding a title prefix with the the_title filter

This happens because the_title filter is run when the the_title() or related function is called to print the title, and prev/next links functions run the same the_title filter. But, the problem here is that you are having general conditions that main post and prev/next fulfil: singular, expired post status and loop. To target the main … Read more

How do I hide the current page’s title?

You can try this function wpb_hidetitle_class($classes) { if ( is_single() || is_page() ) : $classes[] = ‘hidetitle’; return $classes; endif; return $classes; } add_filter(‘post_class’, ‘wpb_hidetitle_class’); CSS code : .hidetitle .entry-title { display : none; } Source http://www.wpbeginner.com/plugins/how-to-hide-post-and-page-titles-in-wordpress-single-pages/

Break out of wordpress filter

Yes, there is such way. All you need to do is to unregister your filter inside it: function highlight_base_category( $classes, $item, $args ) { // most probably you have some if statement here if ( /* YOU CONDITION */ ) { // your code remove_filter( ‘nav_menu_css_class’, ‘highlight_base_category’, 1 ); } return $classes; } add_filter( ‘nav_menu_css_class’, … Read more

Limit RSS feed to previous calendar month

This approach doesn’t work for January: $lastMonthNumber = date( ‘n’, current_time( ‘timestamp’ ) ) – 1; as it would give 1 – 1 = 0. Here’s another suggestion, using the string to time support of the date query: $query->set( ‘date_query’, [ [ ‘after’ => ‘midnight first day of last month’, ‘inclusive’ => true, ], [ … Read more

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