Skip to content

Instantly share code, notes, and snippets.

View elias1435's full-sized avatar
๐Ÿ•‹
Working from home

Md. Elias elias1435

๐Ÿ•‹
Working from home
View GitHub Profile
@elias1435
elias1435 / style.css
Created December 21, 2022 16:31
Checkbox Button Too Small On iPhone
input[type=checkbox],
input[type=radio] {
width: auto;
flex: 0 0 16px;
}
@elias1435
elias1435 / current-user-name.php
Last active December 22, 2022 05:28
display current user name with shortcode. this code will go in functions.php
function show_loggedin_function( $atts ) {
global $current_user, $user_login;
get_currentuserinfo();
add_filter('widget_text', 'do_shortcode');
if ($user_login)
return 'Welcome ' . $current_user->display_name . '!';
else
return '<a href="' . wp_login_url() . ' ">Login</a>';
@elias1435
elias1435 / custom.js
Created January 2, 2023 09:46
How to check if the URL contains a given string?
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
if (window.location.href.indexOf("checkout/?add-to-cart=1375&quantity=1") > -1) {
titleClass = document.querySelector(".find_class_to_add_new_class");
titleClass.classList.add("display-none-info");
}
});
</script>
@elias1435
elias1435 / Remove <p> Tag From Contact Form 7
Created January 5, 2023 11:04
The filter need to add to your wordpress theme functions.php
// removed cf7 <p> tag
add_filter('wpcf7_autop_or_not', '__return_false');
@elias1435
elias1435 / functions.php
Created February 14, 2023 14:53
Remove the vertical bar | in the various action nav groups on Membership Account, Log In widget, and more.
<?php
/**
* Remove the vertical bar | in the various action nav groups on Membership Account, Log In widget, and more.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*
*/
@elias1435
elias1435 / functions.php
Created February 16, 2023 18:28
How to reorder checkout fields on WooCommerce checkout billing or shipping firleds
add_filter( "woocommerce_checkout_fields", "my_reordering_checkout_fields", 15, 1 );
function my_reordering_checkout_fields( $fields ) {
## ---- Billing Fields ---- ##
// Set the order of the fields
$billing_order = array(
'billing_first_name',
'billing_last_name',
'billing_email',
'billing_phone',
'billing_company',
@elias1435
elias1435 / single.php
Created February 24, 2023 10:05
Custom Post Type Related Posts to Your WordPress Site Without Plugins. All the codes need to add in your single.php add this code snippet after the post loop end.
$related = new WP_Query(
array(
'post_type' => 'tutorials', //YOUR CPT SLUG
'category__in' => wp_get_post_categories( $post->ID ),
'posts_per_page' => 3,
'post__not_in' => array( $post->ID ),
)
);
if ( $related->have_posts() ) { ?>
@elias1435
elias1435 / functions.php
Created May 2, 2023 07:15
Add Widget option wordpress - Functions.php
if (function_exists("register_sidebar")) {
register_sidebar();
}
@elias1435
elias1435 / add-body-class-wordpress_functions.php
Created June 16, 2023 12:16
How to Add Category Id to WordPress Body and Post Class This snippet is very handy if you wish to add category ID to WordPress body and post class for ex. targeting CSS styles and such.
function category_id_class($classes) {
global $post;
foreach((get_the_category($post->ID)) as $category)
$classes [] = 'cat-' . $category->cat_ID . '-id';
//if you want to add category slug replace below code
//$classes [] = 'cat-' . $category->slug;
return $classes;
}
add_filter('post_class', 'category_id_class');
add_filter('body_class', 'category_id_class');
@elias1435
elias1435 / add_to_cart_when_match_category.php
Created August 1, 2023 10:41
If you want to redirect after add to cart product only for selected category for this example category is 'main-category' use this below code to functions.php
function custom_add_to_cart_redirect( $url ) {
global $woocommerce;
// Retrieve the product ID from the 'add-to-cart' request parameter.
$product_id = isset( $_REQUEST['add-to-cart'] ) ? intval( $_REQUEST['add-to-cart'] ) : 0;
// Check if the product ID is valid and if the category name is 'main-product'.
if ( $product_id > 0 && has_term( 'main-product', 'product_cat', $product_id ) ) {
// The URL you want to redirect to for 'main-product'.
$redirect_url = 'https://yourdomain.com/add_your_url_here';