Skip to content

Instantly share code, notes, and snippets.

View vikastyagi87's full-sized avatar
🎯
Focusin on code

vikas tyagi vikastyagi87

🎯
Focusin on code
View GitHub Profile
@vikastyagi87
vikastyagi87 / functions.php
Created August 15, 2020 11:50
Illegal string offset ‘width’ and ‘height’ WordPress
//this issue occurs when using image uploaded SVGs
// Image widgets
function wp_get_attachment_metadata_mine($data) {
$res = $data;
if (!isset($data['width']) || !isset($data['height'])) {
$res = false;
}
return $res;
@vikastyagi87
vikastyagi87 / child-theme-css.css
Created July 24, 2020 03:23
Show Secondary Menu Items in Secondary Menu on Mobiles Or show top bar
//force the menu items to remain visible in the secondary header on mobiles using this CSS
//show top bar
@media (max-width: 980px) {
#top-header, div#et-secondary-menu, ul#et-secondary-nav {
display: block !important;
}
#top-header .container {
padding-top: 0.75em !important;
}
}
@vikastyagi87
vikastyagi87 / functions.php
Last active July 20, 2020 19:07
Add Custom JavaScript to Your WordPress Site
//Load JavaScript file for front end from child theme
function my_scripts_method() {
wp_enqueue_script('custom-script', get_stylesheet_directory_uri() . '/js/custom-script.js', array( 'jquery' )
);
}
add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
@vikastyagi87
vikastyagi87 / functions.php
Last active July 20, 2020 18:51
Load js file from in wp-admin only shop manager user through functions.php file
$user = wp_get_current_user();
$allowed_roles = array('shop_manager');
if( array_intersect($allowed_roles, $user->roles ) ) {
//Load JavaScript for admin panel (wp-admin/backend)
add_action( 'admin_enqueue_scripts', 'hide_admin_menu_load_custom_script' );
function hide_admin_menu_load_custom_script() {
wp_enqueue_script('custom_js', get_stylesheet_directory_uri() .'/js/custom.js', array('jquery'));
}
@vikastyagi87
vikastyagi87 / funtions.php
Last active July 20, 2020 18:43
Replace some WooCommerce text
/**
* filter translations, to replace some WooCommerce text with our own
* @param string $translation the translated text
* @param string $text the text before translation
* @param string $domain the gettext domain for translation
* @return string
*/
function replace_some_woocommerce_text($translation, $text, $domain) {
switch ($text) {
case 'Direct bank transfer':