Skip to content

Instantly share code, notes, and snippets.

View yanknudtskov's full-sized avatar

Yan Knudtskov yanknudtskov

View GitHub Profile
@yanknudtskov
yanknudtskov / remove_woocommerce_style_and_scripts.php
Last active February 9, 2019 23:33
Remove WooCommerce Styles and Scripts From http://gregrickaby.com/remove-woocommerce-styles-and-scripts/ #woocommerce #optimization
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
/**
* Remove WooCommerce Generator tag, styles, and scripts from the homepage.
* Tested and works with WooCommerce 2.0+
* @author Greg Rickaby @since 2.0.0
*/
function child_manage_woocommerce_styles()
{
add_action( 'pre_get_posts', 'set_posts_per_page' );
function set_posts_per_page( $query ) {
global $wp_the_query;
if ( ( ! is_admin() ) && ( $query === $wp_the_query ) && ( $query->is_search() ) ) {
$query->set( 'posts_per_page', 3 );
}
elseif ( ( ! is_admin() ) && ( $query === $wp_the_query ) && ( $query->is_archive() ) ) {
$query->set( 'posts_per_page', 5 );
# ------------------------------------------------------------------------------
# | Expires headers |
# ------------------------------------------------------------------------------
# The following expires headers are set pretty far in the future. If you
# don't control versioning with filename-based cache busting, consider
# lowering the cache time for resources such as style sheets and JavaScript
# files to something like one week.
<IfModule mod_expires.c>
@yanknudtskov
yanknudtskov / wp_config_memory_allocation.php
Created February 18, 2014 11:47
WP Memory allocation
define('WP_MEMORY_LIMIT', '128M');
@yanknudtskov
yanknudtskov / redirect-on-login.php
Created February 19, 2014 22:49
Redirect a User After Login You can redirect users who login to your site to another URL based on their role using this snippet. Just add it to your functions.php file:
<?php
function redirect_user_on_role()
{
//retrieve current user info
global $current_user; get_currentuserinfo();
//If login user role is Subscriber
if ($current_user->user_level == 0)
{
wp_redirect( home_url() ); exit;
}
@yanknudtskov
yanknudtskov / set-default-editor.php
Created February 19, 2014 22:50
Set Default Editor Do you prefer to use the HTML editor rather than the Visual Editor when writing posts? Make either of these options your default by adding either of the following lines to your functions.php file:
# Visual Editor as default
add_filter( 'wp_default_editor', create_function('', 'return "tinymce";') );
# HTML Editor as default
add_filter( 'wp_default_editor', create_function('', 'return "html";') );
@yanknudtskov
yanknudtskov / custom-login-logo.php
Created February 19, 2014 22:52
Customize the Dashboard Logo Add your own logo to the dashboard in the backend of WordPress to personalise your installation. This is a great tip for customizing client sites. Just paste the following code into functions.php:
add_action('admin_head', 'custom_logo');
function custom_logo() {
echo '
<style type="text/css"><!--
#header-logo { background-image: url('.get_bloginfo('template_directory').'/images/custom-logo.gif) !important; }
--></style>';
}
@yanknudtskov
yanknudtskov / featured-images-in-rss-feed.php
Created February 19, 2014 22:53
Display Featured Images In RSS Feed A picture tells a thousand words, as they say. Encourage subscribers to visit your site rather than just read your content in their RSS feed by displaying featured images by default:
@yanknudtskov
yanknudtskov / force-100-percent-jpeg-quality.php
Created February 19, 2014 22:56
WordPress automatically compresses images to 90 per cent of the original. While this isn’t such a big deal for most site owners, some people, like photographers, miss this extra 10 per cent. To ensure the images on your site are at 100 per cent quality, add this to your theme’s functions.php file:
add_filter( 'jpg_quality', 'high_jpg_quality' );
function high_jpg_quality() {
return 100;
}
<?php
add_filter( 'tgmsp_caption_output', 'tgm_soliloquy_custom_html', 10, 4 );
function tgm_soliloquy_custom_html( $html, $id, $image, $i ) {
// If the ID doesn't match the one we want to modify, return the default HTML output. Change 324 to your slider ID.
if ( '324' !== $id )
return $html;
// Append custom code output of the caption to do whatever. $i is the number of the slide.
$html .= '<div class="my-custom-class"><p>My custom stuff!</p></div>';