How do I debug a WordPress plugin?

There’s this excellent Q&A at WordPress Stack Exchange, lots of knowledgeable folks explaining their debugging techniques: How do you debug plugins? In the Javascript arena you basically need <script>console.log(‘the value is’ + variable);</script>. And use Google Chrome inspector and/or Firebug. In PHP, it depends on where things are happening or where you want the output. … Read more

WordPress REST API (wp-api) 404 Error: Cannot access the WordPress REST API

UPDATED NEW WAY I also faced similar problem in a local project. I used index.php after my project url and it worked. http://localhost/myproject/index.php/wp-json/wp/v2/posts If it displays a 404 error then update permalinks first (see “Paged Navigation Doesn’t Work” section If it works, maybe you need to enable mod_rewrite, on ubuntu: a2enmod rewrite sudo service apache2 … Read more

How to include pagination in a WordPress Custom Post Type Query

Try the code below: $the_query = new WP_Query( array(‘posts_per_page’=>30, ‘post_type’=>’phcl’, ‘paged’ => get_query_var(‘paged’) ? get_query_var(‘paged’) : 1) ); ?> <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?> <div class=”col-xs-12 file”> <a href=”<?php the_permalink(); ?>” class=”file-title” target=”_blank”> <i class=”fa fa-angle-right” aria-hidden=”true”></i> <?php echo get_the_title(); ?> </a> <div class=”file-description”><?php the_content(); ?></div> </div> <?php endwhile; $big … Read more

Removing and tags in WordPress posts

This happens because of WordPress’s wpautop. Simply add below line of code in your theme’s functions.php file remove_filter( ‘the_content’, ‘wpautop’ ); remove_filter( ‘the_excerpt’, ‘wpautop’ ); For more information:

WooCommerce: Add input field to every item in cart

There is a wordpress plugin called WC Fields Factory for the exact purpose. You can also achieve this by using the following woocommerce hooks woocommerce_before_add_to_cart_button, woocommerce_add_to_cart, woocommerce_cart_item_name,and ‘woocommerce_add_order_item_meta’ like for adding text field to product page function add_name_on_tshirt_field() { echo ‘<table class=”variations” cellspacing=”0″> <tbody> <tr> <td class=”label”><label for=”color”>Name On T-Shirt</label></td> <td class=”value”> <input type=”text” name=”name-on-tshirt” … Read more

Retrieve WordPress root directory path?

Looking at the bottom of your wp-config.php file in the wordpress root directory will let you find something like this: if ( !defined(‘ABSPATH’) ) define(‘ABSPATH’, dirname(__FILE__) . “”); For an example file have a look here: You can make use of this constant called ABSPATH in other places of your wordpress scripts and in … Read more

wp_nav_menu change sub-menu class name?

There is no option for this, but you can extend the ‘walker’ object that WordPress uses to create the menu HTML. Only one method needs to be overridden: class My_Walker_Nav_Menu extends Walker_Nav_Menu { function start_lvl(&$output, $depth) { $indent = str_repeat(“\t”, $depth); $output .= “\n$indent<ul class=\”my-sub-menu\”>\n”; } } Then you just pass an instance of your … Read more