changing variable through filters or action hooks

It won’t work the way you are doing it, but you are close. The reason you have to use a global is that you aren’t setting your $meta variable with the information returned from the filter. This: do_action(‘alter_loop’,$meta); Should be this: $meta = apply_filters(‘alter_loop’,$meta); Note: “Actions” do not return values. “Actions” do things. “Filters” accept … Read more

How apply_filters work in WordPress?

Yes the apply_filters() hook is bit confusing at first when you encounter it. I’ll try my best to explain this: first you need to know that filter hooks allow you to change data before displaying or storing data. Lets take an example function list_array(){ $arr_name = [‘val1’, ‘val2’, ‘val3’]; return $arr_name; } as you can … Read more

Remove classes from post_class()

One way would be to use preg_match and remove classes that matches given patterns, but… Since we know $post_id, we can use your code with a tiny modification: function lsmwp_remove_postclasses($classes, $class, $post_id) { $classes = array_diff( $classes, array( ‘hentry’, ‘post-‘ . $post_id, ‘type-‘ . get_post_type($post_id), ‘status-‘ . get_post_status($post_id), ) ); return $classes; } add_filter(‘post_class’, ‘lsmwp_remove_postclasses’, … Read more

Filter keywords from search query

If I understand you correctly you’re not looking for the wp_search_stopwords filter type of solution. So here’s a modification of the great answer by @kaiser that you referred to: /** * Exclude array of words from all search queries in the front-end * * Modification of http://wordpress.stackexchange.com/a/41100/26350 by @kaiser */ add_filter( ‘posts_search’, function( $search, $q … Read more

How to add data- attribute to tag

There are two ways to solve this. The first one is what you are trying, but you have to print out the value you get. Like this: print get_post_meta(); I don’t recommend this for two reasons: You should keep your templates as simple as possible. Otherwise they become cluttered with fragments of business code which … Read more

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