Skip to content

Instantly share code, notes, and snippets.

View IacopoC's full-sized avatar
🎯
Crunch mode

Iacopo C IacopoC

🎯
Crunch mode
View GitHub Profile
@IacopoC
IacopoC / check-language-wpml.php
Created June 20, 2017 11:32
Check which language are you visualizing in wpml and do some actions
<?php if(ICL_LANGUAGE_CODE=='en'):
// do something
elseif(ICL_LANGUAGE_CODE=='it'):
// do something else
endif; ?>
@IacopoC
IacopoC / custom-qorder.php
Created November 20, 2017 10:47
Order custom query by last word
<?php
$args = [
'posts_per_page' => 10,
'post_type' => 'speaker',
'meta_key' => 'speaker-front-page',
'meta_value' => '1',
'orderby' => 'customq_last_word', //<-- Custom ordering
'order' => 'ASC'
];
@IacopoC
IacopoC / Allow-cpt-in-category-list-archive.php
Last active November 23, 2017 12:07
Allow cpt in category list archive in wordpress
<?php
// Allow cpt in category list
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if( is_category() ) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('nav_menu_item', 'post', 'name_of_post_type'); // don't forget nav_menu_item to allow menus to work!
@IacopoC
IacopoC / enable-dashicons.php
Created January 6, 2018 17:25
Enable Dashicons in the frontend
<?php
// Adding Dashicons in WordPress Front-end
add_action( 'wp_enqueue_scripts', 'load_dashicons_front_end' );
function load_dashicons_front_end() {
wp_enqueue_style( 'dashicons' );
}
@IacopoC
IacopoC / push-instruction
Created February 4, 2018 20:52
Push files in Repo in Git
# Create a new repository on the command line
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/c0ldlimit/vimcolors.git
git push -u origin master
# Push an existing repository from the command line
@IacopoC
IacopoC / get-core-update.php
Created February 21, 2018 20:44
Get core update in Rest Api
<?php
function get_wp_core_updates() {
require_once ABSPATH . '/wp-admin/includes/update.php';
return get_core_updates();
}
add_action( 'rest_api_init', function () {
register_rest_route( 'wp/v2', 'wp-version',array(
'methods' => 'GET',
<?php
// Remove Admin bar
function remove_admin_bar() {
return false;
}
<?php
// disable for posts
add_filter('use_block_editor_for_post', '__return_false', 10);
// disable for post types
add_filter('use_block_editor_for_post_type', '__return_false', 10);
@IacopoC
IacopoC / custom-search-acf-wordpress.php
Created January 15, 2019 14:44 — forked from charleslouis/custom-search-acf-wordpress.php
PHP - Wordpress - Search - wordpress custom search function that encompasses ACF/advanced custom fields and taxonomies and split expression before request
<?php
/**
* [list_searcheable_acf list all the custom fields we want to include in our search query]
* @return [array] [list of custom fields]
*/
function list_searcheable_acf(){
$list_searcheable_acf = array("title", "sub_title", "excerpt_short", "excerpt_long", "xyz", "myACF");
return $list_searcheable_acf;
}
@IacopoC
IacopoC / redirect-custom-page.php
Created September 30, 2019 11:35
Redirect to a custom page when user is logged in based on user role in WP
function hide_the_dashboard()
{
global $current_user;
// is there a user ?
if ( is_array( $current_user->roles ) ) {
// substitute your role(s):
if ( in_array( 'author', $current_user->roles ) ) {
// hide the dashboard:
remove_menu_page( 'index.php' );