Skip to content

Instantly share code, notes, and snippets.

View palicko's full-sized avatar

Pavol Caban palicko

View GitHub Profile
function search_url_rewrite_rule() {
if ( is_search() && !empty($_GET['s'])) {
wp_redirect(home_url("/search/") . urlencode(get_query_var('s')));
exit();
}
}
add_action('template_redirect', 'search_url_rewrite_rule');
@palicko
palicko / Load remote images
Last active March 8, 2016 09:31
Load media files from production server if they don't exist locally
# Load media files from production server if they don't exist locally
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^localsite\.dev$
RewriteRule ^wp-content/uploads/(.*)$ http://remotesite.com/wp-content/uploads/$1 [NC,L]
</IfModule>
# Another way
$('.faq-filter').submit(function(event){
// get values and join them with comma
var vals = $('input[type="checkbox"]:checked').map(
function(i){
return $(this).val();
}).get().join(',');
// push values to hidden field
$('#faq-cats').val(vals);
@palicko
palicko / terms-by-cpt-clauses-filter
Last active December 17, 2016 17:28
Allow to get terms by CPT. Filter terms clauses, so we can get proper terms and posts count related to post type. Usage: add post_type parameter into get_terms() or wp_list_categories() args.
/**
* Extend get terms with post type parameter.
*
* @global $wpdb
* @param string $clauses
* @param string $taxonomy
* @param array $args
* @return string
*/
function custom_terms_clauses( $clauses, $taxonomy, $args ) {
@palicko
palicko / cmb2-show-on-helpers
Last active May 11, 2016 08:54
CMB2 show_on helper functions ( show_on_front_page, show_on_subpage)
/**
* Helper function to check if we edit front page
* @param type $cmb
* @param type $cmb
* @return type
*/
function cmb2_show_if_front_page( $cmb ) {
// Don't show this metabox if it's not the front page template
if ( $cmb->object_id !== get_option( 'page_on_front' ) ) {
return false;
<?php
/*
*
* Usage for the built in 'post' post type:
* unregister_post_type( 'post', 'edit.php' );
*/
function deregister_post_type() {
global $wp_post_types;
$post_type = 'post';
if ( isset( $wp_post_types[ $post_type ] ) ) {
@palicko
palicko / _cookies.scss
Created June 15, 2016 17:46
EU cookies
.eu-cookies {
padding-top: rem-calc(10);
padding-bottom: rem-calc(10);
position: fixed;
left: 0;
bottom: 0;
width: 100%;
color: #fff;
background-color: #000;
z-index: 1000;
.full-width {
width: 100vw;
position: relative;
left: 50%;
right: 50%;
margin-left: -50vw;
margin-right: -50vw;
}
function disable_wp_emojicons() {
// all actions related to emojis
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
@palicko
palicko / gist:65e9bb051df3f72190fe40df3873656c
Last active September 1, 2016 08:59
Hide WP generators
/* Hide WP version strings from scripts and styles
* @return {string} $src
* @filter script_loader_src
* @filter style_loader_src
*/
function mu_remove_wp_version_strings( $src ) {
global $wp_version;
parse_str( parse_url( $src, PHP_URL_QUERY ), $query );
if ( !empty( $query['ver'] ) && $query['ver'] === $wp_version ) {