Passing PHP Variables to JS using Localize Script

Your code should be in an action callback function: function wpse186202_enqueue_scripts(){ wp_enqueue_script( ‘stats’, get_stylesheet_directory_uri() .’/js/t5-demo.js’ , array( ‘jquery’ ), ‘1.0.0’, true ); $categories = implode( ‘, ‘, wp_list_pluck( get_the_category( get_the_ID() ), ‘name’ ) ); $datatoBePassed = array( ‘author’ => get_queried_object()->post_author, ‘category’ => $categories, ‘title’ => single_post_title( ”, false ) ); wp_localize_script( ‘stats’, ‘php_vars’, $datatoBePassed ); … Read more

Get the title before comma

Use strtok(): return strtok( get_the_title(), ‘,’ ); You could also use my function utf8_truncate(). This is a little bit more flexible and it can handle long strings without a comma.

Thumb rating for wordpress – top user

there are varaiables in gd rating to sort query. you can use in URL like : http://www.gdstarrating.com/?gdsr_sort=rating&gdsr_order=desc http://www.gdstarrating.com/?gdsr_sort=review&gdsr_order=desc http://www.gdstarrating.com/category/tutorials/?gdsr_sort=votes&gdsr_order=asc or pass to a query query_posts(“gdsr_sort=rating”); query_posts(“gdsr_sort=review&sort_order=asc”); query_posts(“gdsr_sort=rating&gdsr_multi=3”); query_posts(“gdsr_sort=votes&sort_order=asc&gdsr_multi=3”); you can find more info here : http://www.gdstarrating.com/2009/07/03/how-to-reorder-posts/

Changing the HTML Of the content

The wrapping <p> is applied by a filter called wpautop. You can disable this filter and wrap the content in your desired wrapper, but it’s not really recommended. remove_filter( ‘the_content’, ‘wpautop’ ); remove_filter( ‘the_excerpt’, ‘wpautop’ ); Now you can wrap your content in a DIV for example: <div><?php the_content(); ?></div> But notice that this filter … Read more

Problems migrating WordPress to localhost

First of all what I assume is your local server is not parsing the php properly. So just put a simple phpinfo file and see if that show you the expected page. You can take reference from the following link if you don’t know how to create a phpinfo page – https://mediatemple.net/community/products/dv/204643880/how-can-i-create-a-phpinfo.php-page If the above … Read more

Edit postmeta when user changes user role?

Well, you’re not entirely correct. This code will run, when the action called basic will be called using do_action(‘basic’, …). But… There is no such action in WP core, so your code won’t run at all, I’m afraid. There is hook that might be helpful in your case. It’s called set_user_role and it has 3 … Read more