Remove the slug from published custom post permalinks

/**
* Remove the slug from published custom post permalinks. Only affect our custom post type, though.
*/
function remove_custom_slug( $post_link, $post, $leavename ) {

if ( ‘product’ != $post->post_type || ‘publish’ != $post->post_status ) {
return $post_link;
}

$post_link = str_replace( ‘/’ . $post->post_type . ‘/’, ‘/’, $post_link );

return $post_link;
}
add_filter( ‘post_type_link’, ‘remove_custom_slug’, 10, 3 );

function update_post_request( $query ) {

if ( ! $query->is_main_query() || 2 != count( $query->query ) || ! isset( $query->query[‘page’] ) ) {
return;
}

if ( ! empty( $query->query[‘name’] ) ) {
$query->set( ‘post_type’, array( ‘post’, ‘product’, ‘page’ ) );
}
}
add_action( ‘pre_get_posts’, ‘update_post_request’ );

How to defer Youtube or Vimeo videos in your webpage

First change is that “src” empty like below.
src=””

Second add src URL in “data-src” like bwlow.
data-src=”//www.youtube.com/embed/00000000″

Finally put below jQuery code in your page.

jQuery(window).load(function(){
var vidDefer = document.getElementsByTagName(‘iframe’);
for (var i=0; i<vidDefer.length; i++) {
if(vidDefer[i].getAttribute(‘data-src’)) {
vidDefer[i].setAttribute(‘src’,vidDefer[i].getAttribute(‘data-src’));
}
}
});

How to add & save custom field in My Account Details page in Woocommerce?

add_action( ‘woocommerce_edit_account_form’, ‘my_woocommerce_edit_account_form’ );
add_action( ‘woocommerce_save_account_details’, ‘my_woocommerce_save_account_details’ );

function my_woocommerce_save_account_details( $user_id ) {
update_user_meta( $user_id, ‘dob’, htmlentities( $_POST[ ‘dob’ ] ) );
$user = wp_update_user( array( ‘ID’ => $user_id, ‘user_url’ => esc_url( $_POST[ ‘url’ ] ) ) );
}

function my_woocommerce_edit_account_form() {
$user_id = get_current_user_id();
$user = get_userdata( $user_id );
if ( !$user )
return;
$dob = get_user_meta( $user_id, ‘dob’, true );
$url = $user->user_url;
?>
<fieldset>
<p class=”form-row form-row-thirds”>
<label for=”dob”>Date of Birth:</label>
<input type=”text” id=”datepicker” name=”dob” value=”<?php echo esc_attr( $dob ); ?>” class=”input-text” />
</p>
</fieldset>
<?php
}