Remove category and tag base from WordPress URLs without a plugin?

If you want to remove /category/ from the url, follow these two steps: Go to Settings >> Permalinks and select Custom and enter: /%category%/%postname%/ Next set your Category Base to . Save it and you’ll see your URL changed to this format: http://yourblog.com/quotes/ (Source: http://premium.wpmudev.org/blog/daily-tip-quick-trick-to-remove-category-from-wordpress-url/)

Woocommerce add to cart button redirect to checkout

In WooCommerce 3.6 or later you can use woocommerce_add_to_cart_redirect (props @roman) add_filter (‘woocommerce_add_to_cart_redirect’, function( $url, $adding_to_cart ) { return wc_get_checkout_url(); }, 10, 2 ); Original answer: you can use a filter in functions.php: add_filter (‘add_to_cart_redirect’, ‘redirect_to_checkout’); function redirect_to_checkout() { global $woocommerce; $checkout_url = $woocommerce->cart->get_checkout_url(); return $checkout_url; } it doesn’t seem to work with ajax, but … Read more

wordpress plugin -> Call to undefined function wp_get_current_user()

Apparently this is happening because the file /wp-includes/pluggable which contains the function doesn’t get loaded until after the plugins are loaded. Indeed it is. So wrap whichever thing you’re doing in a function, and hook it onto the plugins_loaded or init hook. (see the wp-settings.php file) Example: add_action(‘init’,’do_stuff’); function do_stuff(){ $current_user = wp_get_current_user(); // … … Read more

Facebook SDK returned an error: Cross-site request forgery validation failed. The “state” param from the URL and session do not match

I found that as long as I enabled PHP sessions before generating the login url, and at the top of the script Facebook eventually redirects to, it works just fine on its own without setting a cookie (as per ale500’s answer). This is using the 5.1 version of the sdk. At the top of both … Read more

PHP- Decode JSON

Try json_decode $array = json_decode($data, true); Then you’ll get an array instead of an object. Example #1 json_decode() examples <?php $json = ‘{“a”:1,”b”:2,”c”:3,”d”:4,”e”:5}’; var_dump(json_decode($json)); var_dump(json_decode($json, true)); ?> The above example will output: object(stdClass)#1 (5) { [“a”] => int(1) [“b”] => int(2) [“c”] => int(3) [“d”] => int(4) [“e”] => int(5) } array(5) { [“a”] => … Read more

Show hide payment methods based on selected shipping method in Woocommerce

The following code example will enable / disable payment gateways based on chosen shipping method. In this example, we have 3 shipping methods and 3 payment gateways. Each selected shipping method will enable only one different payment gateway. add_filter( ‘woocommerce_available_payment_gateways’, ‘payment_gateways_based_on_chosen_shipping_method’ ); function payment_gateways_based_on_chosen_shipping_method( $available_gateways ) { // Not in backend (admin) and Not in … Read more

Hook AJAX in WordPress

First of all you need to add hooks in proper way // For the users that are not logged in add_action( ‘wp_ajax_nopriv_addItemAJAX’, ‘addItemAJAX_callback’ ); // For the users that are logged in: add_action( ‘wp_ajax_addItemAJAX’, ‘addItemAJAX_callback’ ); // ajax handler function addItemAJAX_callback() { // code goes here // since $debugArray is an array, so die(json_encode($debugArray)); // … Read more

Using VBA and VBA-JSON to access JSON data from WordPress API

The JsonConverter is returning a collection of VBA.Collections Scripting.Dictionaries, and Values. In order to understand the output you will have to test the TypeName of all the returned values. The real question is “How to navigate through a json object (or any unknown object for that matter) and access the values within. Immediate Window Using … Read more

Executing PHP code inside a .js file

EDIT: The script type should always be text/javascript as application/javascript may break compatibility with older browsers (I think IE8 and earlier will ignore the script tag with that type). The Content-type, however, should still be application/javascript. You can’t mix in php into a .js file, the way you would with a normal .php file, since … Read more