Not able to change wp_title using add_filter

wp_title filter is deprecated since WordPress 4.4 (see here). You can use document_title_parts instead function custom_title($title_parts) { $title_parts[‘title’] = “Page Title”; return $title_parts; } add_filter( ‘document_title_parts’, ‘custom_title’ ); In custom_title filter, $title_parts contains keys ‘title’, ‘page’ (the pagination, if any), ‘tagline’ (the slogan you specified, only on homepage) and ‘site’. Set “title” the way you … Read more

Filter by one custom field, order by another?

You could use the query to filter the content as you intended by using the ‘meta_query’ with filtering options, and for the order part, just add/modify the following parameters: ‘orderby’ => ‘meta_value’ ‘meta_key’ => ‘location_level1_value’ ‘order’ => ‘ASC’ $wp_query = new WP_Query( array ( ‘post_type’ => ‘listing’, ‘posts_per_page’ => ‘9’, ‘post_status’ => ‘publish’, ‘meta_query’ => … Read more

How to filter users on admin users page by custom meta field?

UPDATE 2018-06-28 While the code below mostly works fine, here is a rewrite of the code for WP >=4.6.0 (using PHP 7): function add_course_section_filter( $which ) { // create sprintf templates for <select> and <option>s $st=”<select name=”course_section_%s” style=”float:none;”><option value=””>%s</option>%s</select>”; $ot=”<option value=”%s” %s>Section %s</option>”; // determine which filter button was clicked, if any and set section … Read more

How to Pass External Variables to Filters/Actions

You have at least two options: Globalize the desired variable, and then reference it inside the callback Wrap the score calculation logic with a function, then reference it inside the callback Globalize the Variable <?php global $score; $score = 42; //Some crazy calculation I don’t want to repeat. function add_score_to_title($title) { global $score; return ‘Quiz … Read more

Filter any HTTP request URI?

Less than an answer, but just a list of things straight from my experience with it – maybe you’ve overlooked something. Debugging the request & its results Without diggin’ too deep into the update process, but the WP HTTP API uses the WP_HTTP class. It also offers a nice thing: A debug hook. do_action( ‘http_api_debug’, … Read more

How to show page content in feed?

First set the post type to display on main feed page i.e. /feed using pre_get_posts hook $q->set(‘post_type’, array(‘post’, ‘page’)); On individual page WordPress shows comment feed then set it to false and display page content in feed. $q->is_comment_feed = false; In feed template WordPress calls the_excerpt_rss() which calls get_the_excerpt() so using excerpt_length filter change the … Read more

Changing WooCommerce Display Price Based on User Role & Category [closed]

Yes there is, you can use the woocommerce_get_price filter hook to filter the value based on user role and return a price accordingly e.g: add_filter(‘woocommerce_get_price’, ‘custom_price_WPA111772’, 10, 2); /** * custom_price_WPA111772 * * filter the price based on category and user role * @param $price * @param $product * @return */ function custom_price_WPA111772($price, $product) { … Read more

the_content and is_main_query

To be honest, the function in_the_loop() is what you are looking for: add_filter( ‘the_content’, ‘custom_content’ ); function custom_content( $content ) { if ( in_the_loop() ) { // My custom content that I add to the_content() } return $content; } What in_the_loop does is to check if global for $wp_query (that is the main query object) … Read more

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