Do you want to explode or split a string in JavaScript

If you want to break the string by space or certain character so you can use javascript split() function for this. Below is the example to split/break the string through space.

<script type="text/javascript">
        var StringtoBreak = "The quick brown fox jumps over the lazy dog.";
        var stringArray = StringtoBreak.split(" ");
 
    </script>

You can also limit the split function so I can only split the sting with number of occurrence and leave the remaining string after that.

<script type="text/javascript">
        var StringtoBreak = "The quick brown fox jumps over the lazy dog.";
        var stringArray = StringtoBreak.split(" ",2);
 
    </script>

Above code will split the string with only first 2 occurrence and leave the remaining string in third element of the array.

How to get WooCommerce Product Category Link by ID?

You can use get_term_link to get the URL of Product. Category ID needed to be converted to an integer.

     $woo_cat_id_int = (int)$woo_cat_id;
     $term_link = get_term_link( $woo_cat_id, 'product_cat' );
     echo '<a href="' . esc_url( $term_link ) . '">' . $term-&gt;name . '</a>';

If you have the term Object then you can simply get the link by using below code

    $term_link = get_term_link( $term );
    echo '<a href="' . esc_url( $term_link ) . '">' . $term-&gt;name . '</a>';

How to Remove <p> and <br /> from Contact Form 7

Do you want to remove all the auto generated tags like
<p>, <br /> etc. from Contact Form 7? You just need to add small snippet in wp-config.php

define('WPCF7_AUTOP', false );

OR

You can add below snippet in functions.php file in your theme folder.

add_filter( 'wpcf7_autop_or_not', '__return_false' );

Get Home Page ID or Blog Page ID in WordPress

WordPress is number one CMS and have very useful options. You can get Home/Front Page ID by using following code

$frontpage_ID = get_option( 'page_on_front' );

Above Code will return the ID of the Home/Front page we have set for the site, or return 0 if Home/Front page hasn’t been set.

Also you can get the Blog Page ID by using following code

$blogpage_ID = get_option( 'page_for_posts' );

Get Permalink by Page title or slug

Usually we grab a page Permalink through page ID but sometimes we had a case to grab Permalink through Page Slug or Page Title, So Below are the easiest way to grab the permalink for a page through page title or page slug.

 get_permalink( get_page_by_path( 'case-studies' ) );  
 get_permalink( get_page_by_title( 'Case Studies' ) );

How to remove Page Title at the shop page Storefront Woocommerce

To remove Page Title from the woocommerce main(shop) page with storefront theme you need to add following code in functions.php.

   function hide_shop_page_title() {
      return false;
  }
  add_filter( 'woocommerce_show_page_title' , 'hide_shop_page_title' );

How to remove Storefront sticky add to cart from Single Product Page

New Storefront theme have sticky add to cart on Single Product Page enabled by default if you want to remove this you just need to add below code in your functions.php.

remove_action( 'storefront_after_footer', 'storefront_sticky_single_add_to_cart', 999 );

Display all custom post type posts from a custom taxonomy

Display Posts(Custom Post Type) from Specific Category (Custom Taxonomy)

You can get all the posts of custom post type from a category (custom taxonomy) by category slug. You can add below code in the page template or theme file where you want to add Posts.

   <!--?php
    $args = array('post_type' =------> 'custom_post_type',
        'tax_query' =&gt; array(
            array(
                'taxonomy' =&gt; 'custom_taxonomy',
                'field' =&gt; 'slug',
                'terms' =&gt; 'slug_of_custom_taxonomy',
            ),
        ),
     );
 
     $loop = new WP_Query($args);
     if($loop-&gt;have_posts()) {
 
        while($loop-&gt;have_posts()) : $loop-&gt;the_post();
            echo '
 
 
 
 
<div class="post"><a href="'.get_permalink().'">'.get_the_title().'</a>
';
            echo '
'.get_the_excerpt().'
 
';
            echo '<a href="'.get_permalink().'">View Details</a></div>
 
 
 
 
';
        endwhile;
     }else{
        echo '
 
 
 
 
<h2>No posts found in this Custom Taxonomy</h2>
 
 
 
 
';
     }
?&gt;

Display All custom taxonomy and there custom post types underneath those

You can list all posts of custom post type and arrange them by the custom taxonomy. You can add below code in the page template or theme file where you want to add Posts.

<!--?php
    $custom_taxonomys = get_terms('custom_taxonomy');
 
    foreach($custom_taxonomys as $custom_taxonomy) {
        $args = array('post_type' =------> 'custom_post_type',
            'tax_query' =&gt; array(
                array(
                    'taxonomy' =&gt; 'custom_taxonomy',
                    'field' =&gt; 'slug',
                    'terms' =&gt; $custom_taxonomy-&gt;slug,
                ),
            ),
         );
 
         $loop = new WP_Query($args);
         if($loop-&gt;have_posts()) {
 
            echo '
 
 
 
 
<h2>'.$custom_taxonomy-&gt;name.'</h2>
 
 
 
 
';
 
            while($loop-&gt;have_posts()) : $loop-&gt;the_post();
                echo '
 
 
 
 
<div class="post"><a href="'.get_permalink().'">'.get_the_title().'</a>
';
                echo '
'.get_the_excerpt().'
 
';
                echo '<a href="'.get_permalink().'">View Details</a></div>
 
 
 
 
';
            endwhile;
 
         }else{
            echo '
 
 
 
 
<h2>'.$custom_taxonomy-&gt;name.'</h2>
 
 
 
 
';
            echo '
 
 
 
 
<h2>No posts found in this Custom Taxonomy</h2>
 
 
 
 
';
         }
    }
?&gt;

How to Change Add To Cart button text in wooCommerce

Do you want to change the ‘Add to Cart’ button text in Woocommerce? Like you want to update the text from ‘Add to Cart’ to ‘Add to Basket’, ‘Buy Now’ or View Details then you just add below snippet into your theme’s functions.php file.


add_filter('single_add_to_cart_text', 'bpt_add_cart_button_text');
  
function bpt_add_cart_button_text() {
    return __('Buy Now', 'woocommerce');
}