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

Get cart item name, quantity all details woocommerce

Try this : <?php global $woocommerce; $items = $woocommerce->cart->get_cart(); foreach($items as $item => $values) { $_product = wc_get_product( $values[‘data’]->get_id()); echo “<b>”.$_product->get_title().'</b> <br> Quantity: ‘.$values[‘quantity’].'<br>’; $price = get_post_meta($values[‘product_id’] , ‘_price’, true); echo ” Price: “.$price.”<br>”; } ?> To get Product Image and Regular & Sale Price: <?php global $woocommerce; $items = $woocommerce->cart->get_cart(); foreach($items as $item => … Read more

How can I get the current page name in WordPress?

The WordPress global variable $pagename should be available for you. I have just tried with the same setup you specified. $pagename is defined in the file wp-includes/theme.php, inside the function get_page_template(), which is of course is called before your page theme files are parsed, so it is available at any point inside your templates for … Read more

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

Trying to get contact form 7 post data to debug to screen

You can’t just dump this data to the screen, because it’s part of an ajax function. You can however dump it to the error log and tail it in bash, or view the output of the log with FTP. If you do this instead: add_action( ‘wpcf7_before_send_mail’, ‘my_process_cf7_form_data’ ); function my_process_cf7_form_data() { $submission = WPCF7_Submission::get_instance(); if … 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=”https://stackoverflow.com/questions/41738362/<?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