Skip to content

Instantly share code, notes, and snippets.

<?php
// Using 'post_like' custom WP_Query argument:
// https://hwk.fr/code/ajouter-un-argument-post-title-content-like-dans-wp-query
$query = new WP_Query(array(
'post_type' => 'page',
'posts_per_page' => 1,
'post_like' => array(
'column' => 'post_content',
array(
<?php
add_filter('upload_mimes', 'hwk_upload_mimes_types');
function hwk_upload_mimes_types($mimes){
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
<?php
add_filter('sanitize_file_name', 'hwk_sanitize_file_name');
function hwk_sanitize_file_name($input){
$path = pathinfo($input);
$extension = (isset($path['extension']) && !empty($path['extension'])) ? $path['extension'] : '';
$file = (!empty($extension)) ? preg_replace('/.' . $extension . '$/', '', $input) : $input;
return sanitize_title(str_replace('_', '-', $file)) . ((!empty($extension)) ? '.' . $extension : '');
}
<?php
add_filter('posts_where', 'hwk_wp_query_post_like', 10, 2);
function hwk_wp_query_post_like($where = '', &$wp_query){
global $wpdb;
if(!$post_like = $wp_query->get('post_like'))
return $where;
if(is_string($post_like))
return $where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'%' . esc_sql($wpdb->esc_like($post_like)) . '%\'';
<?php
add_action('init', 'hwk_add_rewrite_rule');
function hwk_add_rewrite_rule(){
add_rewrite_tag('%page_filter%', '([^&]+)');
add_rewrite_rule('^contact/([^/]*)/?', 'index.php?pagename=contact&page_filter=$matches[1]', 'top');
}
// example.com/contact/commercial
// page-contact.php:
<?php
add_filter('is_protected_meta', '__return_false');
<?php
add_filter('acf/settings/remove_wp_meta_box', '__return_false');
<?php
add_action('init', 'hwk_deregister_builtin_post_type');
function hwk_deregister_builtin_post_type(){
global $wp_post_types;
$unregister = array(
'post',
'page',
);
<?php
add_action('login_enqueue_scripts', '_pit_login_logo_style');
function _pit_login_logo_style(){ ?>
<style type="text/css">
#login h1 a, .login h1 a {
background-image: url(<?php header_image(); ?>);
height:80px;
width:320px;
background-repeat: no-repeat;
acf.add_action('append_field/type=flexible_content', function(e){
if(e.attr('data-key') == 'field_flexible_template'){
acf.fields.flexible_content.doFocus(e).add('sub-template-1');
acf.fields.flexible_content.doFocus(e).add('sub-template-2');
}
});