Skip to content

Instantly share code, notes, and snippets.

@alanef
Last active April 16, 2019 10:18
Show Gist options
  • Select an option

  • Save alanef/4f3229278e44291f1103ada532f0f6ff to your computer and use it in GitHub Desktop.

Select an option

Save alanef/4f3229278e44291f1103ada532f0f6ff to your computer and use it in GitHub Desktop.
Example custom code plugin to change header sizes set by theme

Install customcode.php in your plugin directory or better create a subdirectory called custom code and put this in there. And activate the plugin.

Change names and sizes as required

After installing you will need to regenerate thumbnails - there is a plugin that does that https://en-gb.wordpress.org/plugins/regenerate-thumbnails/

Use the structure to add other custom tweaks without changing teh them's functions.php

Not tested - but should work - any problems let me know so I can tweak...

<?php
/**
*
* Plugin Name: Custom Code
* Plugin URI: https://fullworks.net/products/custom-plugin-development/
* Description: Custom Code
* Version: 0.0.0
* Author: Fullworks
* Author URI: http://fullworks.net/
* License: GPL-3.0+
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
*
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
add_action( 'after_setup_theme', function () {
remove_image_size( 'header-image' ); // change this to remove the already theme registered size - change the name as required
add_image_size( 'header-image', 1600, 600, true ); // cahnge the width, height and crop as required
}, 99 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment