Skip to content

Instantly share code, notes, and snippets.

View Hexodus's full-sized avatar

Adrian Maleska Hexodus

  • Wiesbaden - Germany
View GitHub Profile
yarn create nuxt-app <my-project>
@Hexodus
Hexodus / wp_custom_excrept_length.php
Created August 2, 2017 16:51
Wordpress set custom excrept length in words.
<?php
//custom excrept length in words
add_filter( 'excerpt_length', function(){ return 40; }, 999 );
?>
@Hexodus
Hexodus / get_site_thumbnail_instead_of_post.php
Created August 2, 2017 14:48
Wordpress. Method to get the site features image instead of the loop ones. Useful for blogs where usually the_post_thumbnail() would call the first loop image thumbnail.
<?php
$img = wp_get_attachment_image_src(get_post_thumbnail_id(get_option('page_for_posts')),'full');
$featured_image = $img[0];
?>
@Hexodus
Hexodus / wordpress_change_image_compression.php
Last active August 2, 2017 10:14
Change Wordpress default image compression percentage. I'm most happy with 90% ;) Keep in mind that it applies only to new uploaded images - old ones have to be regenerated.
<?PHP
add_filter('jpeg_quality', function($arg){return 90;});
?>
@Hexodus
Hexodus / reactivate_admin_toolbar.php
Last active August 2, 2017 09:36
Reactivate Wordpress admin toolbar when it was hidden by the parent theme (idiots are everywhere!). In this case I reactivate it only for admins. Place this code in your functions.php (i.e. in your child theme's folder)
<?php
if( current_user_can('administrator'))
add_filter( 'show_admin_bar', '__return_true' , 1000 );
?>
@Hexodus
Hexodus / add_custom_image_sizes_2wordpress.php
Last active August 2, 2017 09:36
Add custom images sizes to Wordpress and Admin area. Found solution here: https://havecamerawilltravel.com/photographer/wordpress-resize-thumbnails Place this code in your functions.php (i.e. in your child theme's folder)
<?php
add_image_size( 'homepage-thumb', 270, 175, false ); //soft crop = resize
add_image_size( 'search-thumb', 150, 150, true ); //hard crop
add_filter( 'image_size_names_choose', 'my_custom_sizes' );
function my_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'homepage-thumb' => __( 'Homepage Thumb' ),
'search-thumb' => __( 'Search Thumb' ),
) );
@Hexodus
Hexodus / htaccess_ssl_wp
Last active July 27, 2017 11:07
Force SSL for Wordpress via htaccess. Works for both single Blogs or Multisite. Just add below RewriteEngine On RewriteBase / #Force SSL code here On shared hosting it could produce to much redirections - when you convert from http to https. So it's better to rewrite all url's first (but after switching ssl on your hosting on) to reduce them. Th…
#Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
@Hexodus
Hexodus / globals_vs_constants_vs_define.php
Last active April 23, 2017 21:02
$GLOBALS vs define() vs const; It depends. I would go for `define()` because it has a more compact syntax in usage. But `define()` can only hold scalar values in PHP < 7.0 In case you need i.e. an associative array you have no other choice then to go for ` $GLOBALS` or use PHP >=7.0. From http://stackoverflow.com/questions/10691404/php-best-way-…
// Storing a single value works fine with define
define( 'ROOT_DIR', dirname(dirname(__FILE__)) . '/' );
// But not for complex data types like this array
$USERPIC_PARAMS = array(
"user_root" => "images/users",
"padding_length" => 8,
"split_length" => 4,
"hash_length" => 12,
"hide_leftover" => false