Skip to content

Instantly share code, notes, and snippets.

View AlexWebLab's full-sized avatar

Alex AlexWebLab

View GitHub Profile
@AlexWebLab
AlexWebLab / .htaccess
Last active August 16, 2016 09:31
How to permanently redirect all the pages of a WordPress website to a new domain
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !.*NEWDOMAIN\.COM$ [NC]
RewriteRule ^(.*)$ http://NEWDOMAIN.COM/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
@AlexWebLab
AlexWebLab / flexbox_wrapper_ie_10_11_fix.css
Last active August 16, 2016 09:31
In IE 10-11, min-height declarations on flex containers work to size the containers themselves, but their flex item children do not seem to know the size of their parents. They act as if no height has been set at all.
ul, li { margin: 0; padding: 0; }
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
.flexbox_wrapper_ie_10_11_fix {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
@AlexWebLab
AlexWebLab / facebook_page_latest_post_no_php_sdk.php
Created December 7, 2016 08:17 — forked from biojazzard/facebook_page_latest_post_no_php_sdk.php
Get Latest Post From a Facebook Page without PHP SDK (Graph Version v2.5)
<?php
/*
1.- Create an App.
2.- Go to: https://developers.facebook.com/tools/explorer/
+ Select your new created app on the right top.
+ Select "Get App Token"
@AlexWebLab
AlexWebLab / file.sql
Last active April 24, 2017 06:06
WordPress SQL administrator user creation
SET @user_login := 'admin_user';
SET @user_pass := 'Q9xiHgzZ';
SET @user_email := 'admin_user@email.com';
INSERT INTO `wp_users`
(`user_login`, `user_pass`, `user_email`, `user_registered`)
VALUES
(@user_login, MD5(@user_pass), @user_email, now());
SELECT @user_id := LAST_INSERT_ID();
INSERT INTO `wp_usermeta`
(`user_id`, `meta_key`, `meta_value`)
@AlexWebLab
AlexWebLab / functions.php
Last active March 8, 2017 03:25
Remove Multilingual Content Setup metabox on every post type edit page in WordPress admin
<?php
add_action('admin_head', 'disable_icl_metabox');
function disable_icl_metabox() {
$screen = get_current_screen();
remove_meta_box('icl_div_config',$screen->post_type,'normal');
}
@AlexWebLab
AlexWebLab / order_associative_array_by_a_specific_column.php
Last active March 8, 2017 03:25
Order an associative array by a specific column.
<?php // On this example I'm extracting all the WordPress categories from a parent category and order them by an additional custom field named "order" assigned to the category taxonomy. ?>
<?php
$siblings = get_term_children($current_cat->term_id, 'category');
$siblings_list = array( array() );
$i=0;
foreach ($siblings as $sibling) {
$sibling_object = get_term_by( 'id', $sibling, 'category');
$siblings_list[$i]['name'] = $sibling_object->name;
$siblings_list[$i]['url'] = get_term_link( $sibling, 'category');
$siblings_list[$i]['order'] = get_field('order', $sibling_object->taxonomy.'_'.$sibling_object->term_id);
@AlexWebLab
AlexWebLab / file.php
Last active March 22, 2019 05:23
Create Bootstrap tabs from Advanced Custom Fields
<div id="with_tabs_container" class="flex no-flex-xs-block">
<div class="left_column">
<?php if ( have_rows('tabs') ) { ?>
<ul class="list-unstyled green_tablist" role="tablist">
<?php $i=1; while ( have_rows('tabs') ) { the_row(); ?>
<li role="presentation" class="<?php if(1==$i) echo 'active'; ?>">
<a href="#tab_pane_<?php echo $i; ?>" role="tab" data-toggle="tab" title="<?php echo esc_attr(get_sub_field('tab_name')); ?>"><?php the_sub_field('tab_name'); ?></a>
</li>
@AlexWebLab
AlexWebLab / functions.php
Last active April 24, 2017 05:55
Extend WordPress search to include advanced custom fields
<?php
/**
* Extend WordPress search to include custom fields
*/
/**
* Join posts and postmeta tables
*
* http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_join
*/
@AlexWebLab
AlexWebLab / functions.php
Last active April 24, 2017 06:19
Resizing and showing images from ACF in WordPress theme development for page load performance optimisation
<?php
add_action( 'after_setup_theme', 'custom_image_sizes' );
function custom_image_sizes() {
add_image_size( 'image-1400px-wide', 1400 ); // 1400 pixels wide (and unlimited height)
add_image_size( 'image-700px-wide', 700 ); // 700 pixels wide (and unlimited height)
add_image_size( 'image-350px-wide', 350 ); // 350 pixels wide (and unlimited height)
}
@AlexWebLab
AlexWebLab / style.css
Last active September 12, 2023 17:05
Retina displays CSS background image
.logo_background {
background-image: url('../img/logo@1x.png');
background-position: center center;
background-repeat: no-repeat;
background-size: 80px 40px; /* size of the logo image @ 1x */
}
@media /* only for retina displays */
only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and (min--moz-device-pixel-ratio: 2),
only screen and (min-device-pixel-ratio: 2),