How to Remove menu item has children? in WordPress

add_filter('nav_menu_css_class', 'special_nav_class', 10, 2);
function special_nav_class($classes, $item){
    if(($key = array_search('menu-item-has-children', $classes)) !== false) {
        unset($classes[$key]);
    }
    return $classes;
}

Add this to functions.php it will remove the ‘menu-item-has-children’ class to has child

How to create REST API For Primary Menu

add_action( 'rest_api_init', function () {
register_rest_route( 'myroutes', '/menu', array(
	'methods' => 'GET',
	'callback' => 'wp_menu_route',
	) );
} );
function wp_menu_route() {
	$menuLocations = get_nav_menu_locations();
	$menuID = $menuLocations['primary'];
	register_nav_menus();
	$primaryNav = wp_get_nav_menu_items($menuID);
		if($primaryNav){
			foreach($primaryNav as $index=>$singlenav){
				if($singlenav->type=='post_type'){
				$primaryNav[$index]->slug=get_post_url($singlenav->url);
				$primaryNav[$index]->page_template=get_selected_page_template($singlenav->url);
				}
			}
		}
	return $primaryNav;
}
function get_post_url( $object ) {
	$postid = url_to_postid($object);
	$post_slug = get_post_field( 'post_name', $postid);
	return stripslashes_deep($post_slug);
}
function get_selected_page_template( $object ) {
	$postid = url_to_postid($object);
	$page_template = get_post_field( '_wp_page_template', $postid);
	return stripslashes_deep($page_template);
}

How to get Star rating / Review in WooCommerce

global $product;
$average = $product->get_average_rating();
	$html = '';
	$html .= '<div class="rating_and_brand">';
	    $html .= '<div class="product_star_div_main">';
	        $html .= '<div class="star-rating">';
	            $html .= '<span style="width:'.( ( $average / 5 ) * 100 ) . '%">'.$average.'</span>';
	            $html .= '</div>';		                            
	        $html .= '</div>';
	$html .= '</div>';
	echo $html;

Share post on Twitter with title, thumb, and content

Put in your theme function.php

function insert_image_src_rel_in_head() { global $post; $id = $post->ID - 1; if ( !is_singular()) //if it is not a post or a page return; if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image $default_image=""; //replace this with a default image on your server or an image in your media library echo ''; } else{ $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $id ), 'medium' ); echo ''; } echo " "; } add_action( 'wp_head', 'insert_image_src_rel_in_head', 5 );

String functions

(1) Add C slashes
Returns a string with backslashes in front of the specified characters $str = addcslashes("Hello World!","W"); echo($str); Output : Hello \World!
(2) Add slashes
Returns a string with backslashes in front of predefined characters $str = addslashes('What does "yolo" mean?'); echo($str); Output : What does \"yolo\" mean?
(3) Bin2hex
Converts a string of ASCII characters to hexadecimal values $str = bin2hex("Hello World!"); echo($str); Output : 48656c6c6f20576f726c6421