Skip to content

Instantly share code, notes, and snippets.

@hauge75
hauge75 / functions.php
Created April 11, 2016 23:15
WPML language selector in menu - hide current language
<?php
// Filter wp_nav_menu() to add additional links and other output
add_filter('wp_nav_menu_items', 'new_nav_menu_items', 10, 2);
function new_nav_menu_items($items, $args) {
// add $args->theme_location == '[location]' in the conditional if we want to specify the menu location.
if (function_exists('icl_get_languages') && $args->theme_location == 'primary-menu') {
$languages = icl_get_languages('skip_missing=0');
if(!empty($languages)){
@hauge75
hauge75 / functions.php
Last active April 11, 2016 23:22
Redirects wordpress author archives
<?php
//Redirects author archives, DON'T check "Disable Extra User Archives" in iThemes security
add_action( 'template_redirect', 'my_redirect_author_archive' );
function my_redirect_author_archive() {
if ( is_author() ) {
wp_redirect( home_url(), 302 );
exit;
}
@hauge75
hauge75 / functions.php
Created April 20, 2016 21:15
Give double weight to current and future events in relevanssi search (Relevanssi & Events Manager)
add_filter('relevanssi_match', 'date_weights');
function date_weights($match) {
$EM_Event = em_get_event($match->doc, 'post_id');
$enddate = $EM_Event->event_end_date;
$yesterday = time() - 24*60*60;;
if (strtotime($enddate) > $yesterday) {
$match->weight = $match->weight * 2;
}
else {
@hauge75
hauge75 / functions.php
Last active April 30, 2016 17:52
Changes the text labels for Google Calendar and iCal buttons on a single event page for The Events Calendar by Modern Tribe
<?php
// Changes the text labels for Google Calendar and iCal buttons on a single event page
remove_action('tribe_events_single_event_after_the_content', array('Tribe__Events__iCal', 'single_event_links'));
add_action('tribe_events_single_event_after_the_content', 'customized_tribe_single_event_links');
function customized_tribe_single_event_links() {
if (is_single() && post_password_required()) {
return;
}
@hauge75
hauge75 / functions.php
Created June 10, 2016 12:55
Change WordPress Email “Send From” Settings
function mail_filter_wp_mail_from($email){
return "your@email.com";
}
add_filter("wp_mail_from", "mail_filter_wp_mail_from");
@hauge75
hauge75 / functions.php
Created July 18, 2016 09:10
Rename slug for existing custom post type in childtheme - Wordpress
//* change slug for post type
$args = get_post_type_object("post_type_name");
$args->rewrite["slug"] = "new_slug";
register_post_type($args->name, $args);
<?php
/**
* Plugin Name: Multisite: Passwort Reset on Local Blog
* Plugin URI: https://gist.github.com/eteubert/293e07a49f56f300ddbb
* Description: By default, WordPress Multisite uses the main blog for passwort resets. This plugin enables users to stay in their blog during the whole reset process.
* Version: 1.0.0
* Author: Eric Teubert
* Author URI: http://ericteubert.de
* License: MIT
*/
@hauge75
hauge75 / single-product.php
Created January 30, 2018 12:38
Woocoomerce if in stock
global $product;
if ($product->is_in_stock()) {
//Do if product is in stock
}
@hauge75
hauge75 / functions.php
Last active February 29, 2020 12:20
White label Soliloquy slider
// Register sliderstyle sheet.
//add_action( 'wp_enqueue_scripts', 'theme_register_slider_style' );
/**
* Register style sheet.
*/
/*
function theme_register_slider_style() {
wp_register_style( 'slider', get_stylesheet_directory_uri() . '/css/slider.min.css', 'soliloquy-style-css' );
wp_enqueue_style( 'slider' );
@hauge75
hauge75 / Sortabel-ACF-Post-Object.txt
Created October 7, 2022 21:06
Display Sortabel ACF Post Object field in admin column
/*
* Add columns to post list
*/
function add_acf_columns ( $columns ) {
return array_merge ( $columns, array (
'custom_column' => __ ( 'Custom column' ),
) );
}
add_filter ( 'manage_postname_posts_columns', 'add_acf_columns' );