Skip to content

Instantly share code, notes, and snippets.

View kirandash's full-sized avatar

Kiran Dash kirandash

View GitHub Profile
function add_marker( $marker, map ) {
// var
var latlng = new google.maps.LatLng( $marker.attr('data-lat'), $marker.attr('data-lng') );
// create marker
var marker = new google.maps.Marker({
position : latlng,
map : map,
icon: "http://de-vos.nl//wp-content/themes/devos/img/mapMarker.png"
@kirandash
kirandash / Mark parent navigation active when on custom post type single page
Created July 22, 2016 06:58
Mark (highlight) custom post type parent as active item in Wordpress Navigation. When you visit a custom post type's single page, the parent menu item (the post type archive) isn't marked as active. This code solves it by comparing the slug of the current post type with the navigation items, and adds a class accordingly.
add_action('nav_menu_css_class', 'add_current_nav_class', 10, 2 );
function add_current_nav_class($classes, $item) {
// Getting the current post details
global $post;
// Getting the post type of the current post
$current_post_type = get_post_type_object(get_post_type($post->ID));
$current_post_type_slug = $current_post_type->rewrite['slug'];
@kirandash
kirandash / Filter p tags with images - WordPress
Created July 29, 2016 07:42
In case you want to have <img> in your content but not have them get "Auto P'd" like WordPress likes to do.
<?php
/* Filter p tags with images */
function kd_filter_ptags_on_images($content) {
$content = preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
return preg_replace('/<p>\s*(<iframe .*>*.<\/iframe>)\s*<\/p>/iU', '\1', $content);
}
add_filter('acf_the_content', 'kd_filter_ptags_on_images');
add_filter('the_content', 'kd_filter_ptags_on_images');
?>
<?php
//functions.php file function
function get_menu_parent_ID($menu_name){
if(!isset($menu_name)){
return "No menu name provided in arguments";
}
$menu_slug = $menu_name;
$locations = get_nav_menu_locations();
$menu_id = $locations[$menu_slug];
@kirandash
kirandash / CUSTOM LANGUAGE SWITCHER
Last active July 16, 2023 05:59
Custom language switcher for the wpml plugin that shows the language code
<?php
// IN FUNCTIONS.PHP FILE CUSTOM LANGUAGE SWITCHER
function language_selector_flags(){
$languages = icl_get_languages('skip_missing=0&orderby=code');
if(!empty($languages)){
echo '<ul class="menu language-menu">';
foreach($languages as $l){
if($l['active'] == 1){ $class = 'lang_sel_sel'; }
elseif ($l['active'] == 0) {
/**
* Extend WordPress search to include custom fields
*
* http://adambalee.com
*/
/**
* Join posts and postmeta tables
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_join
@kirandash
kirandash / Add remove action via functions.php
Created August 17, 2016 05:47
Add remove action via functions.php for child theme
function primrose_child_add_remove(){
remove_action( 'woocommerce_before_shop_loop', 'primrose_woocommerce_subcategories', 10 );
add_action( 'woocommerce_before_shop_loop', 'primrose_child_woocommerce_subcategories', 10 );
}
add_action('init','primrose_child_add_remove');
@kirandash
kirandash / WooCommerce - get category for product page
Last active August 19, 2016 04:59
A WC product may belong to none, one or more WC categories. Supposing you just want to get one WC category id.
global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ($terms as $term) {
$product_cat_id = $term->term_id;
break;
}
@kirandash
kirandash / WooCommerce - add text after price
Last active September 6, 2016 08:01 — forked from jameskoster/functions.php
WooCommerce - add text after price
functions.php
/**
* WooCommerce - add symbol after price
*/
add_filter( 'woocommerce_get_price_html', 'kd_custom_price_message' );
add_filter( 'woocommerce_cart_item_price', 'kd_custom_price_message' );
add_filter( 'woocommerce_cart_item_subtotal', 'kd_custom_price_message' ); // added
add_filter( 'woocommerce_cart_subtotal', 'kd_custom_price_message' ); // added
add_filter( 'woocommerce_cart_total', 'kd_custom_price_message' ); // added
@kirandash
kirandash / functions.php
Created September 7, 2016 08:29
custom logo
<?php
// Add theme support for custom logo as it is required for WordPress 4.5 onwards
add_theme_support( 'custom-logo', array(
'width' => 367,
'height' => 92,
'flex-width' => true,
'flex-height' => true
)
);