Add an Image Cropper to your WordPress image upload fields
Add an image cropper to your WordPress site and set image requirements like crop aspect ratio and image target size. Use CropGuide and receive better images.
Adding an image cropper to WordPress lets your users customize their images before upload, ensuring photos are uploaded precisely matching your requirements, saving you time fixing user images on the backend.
This guide helps you add CropGuide to any WordPress file upload field, whether that field is located on the front-end, in the admin, or in the Gutenberg content editor.
Installing CropGuide
To get started we first need to create a CropGuide account
Log in to CropGuide and add your domain to the control panel.
The control panel will generate a unique script for your domain similar to the one shown below:
<script>
(function (w, d) {
w.$cropguide = ['GFFFYQ'];
var s = d.createElement('script');
s.async = true;
s.src = 'https://cdn.cropguide.io/l.js';
d.head.append(s);
})(window, document);
</script>
With your CropGuide account created let’s log in to the WordPress admin.
-
In the main navigation click
-
In the Appearance sub menu click
-
Click functions.php file in the files list on the right.
-
Select the central text area and scroll to the end.
-
Copy the script shown to the text area.
<?php
// This will load the CropGuide service script
function cropguide_scripts() {
?>
<script>
(function (w, d) {
w.$cropguide = ['GFFFYQ'];
var s = d.createElement('script');
s.async = true;
s.src = 'https://cdn.cropguide.io/l.js';
d.head.append(s);
})(window, document);
</script>
<?php
}
add_action('wp_head', 'cropguide_scripts');
?>
-
Replace the key
123ABCwith your unique domain key as shown on your CropGuide domain page. -
Click to save the changes.
That’s it, CropGuide now loads on your WordPress pages.
Test it out by opening a page with a form and selecting an image.
We can customize the WordPress script to only activate CropGuide in specific situations.
Loading CropGuide in the admin only
If you want to use CropGuide in the WordPress admin you have to replace wp_enqueue_script with admin_enqueue_scripts
<?php
// This will load the CropGuide service script
function cropguide_scripts() {
?>
<script>
(function (w, d) {
w.$cropguide = ['GFFFYQ'];
var s = d.createElement('script');
s.async = true;
s.src = 'https://cdn.cropguide.io/l.js';
d.head.append(s);
})(window, document);
</script>
<?php
}
// This will load the CropGuide service script on the admin
add_action('admin_head', 'cropguide_scripts');
?>
Load CropGuide only for specific users
If you only want to load CropGuide for users with specific roles we can do that by getting the current user and checking for the required roles.
<?php
// This will load the CropGuide service script
function cropguide_scripts() {
// But only for authors, editors, and administrators
$user = wp_get_current_user();
$allowed_roles = array('author', 'editor', 'administrator');
if (array_intersect($allowed_roles, $user->roles)) {
?>
<script>
(function (w, d) {
w.$cropguide = ['GFFFYQ'];
var s = d.createElement('script');
s.async = true;
s.src = 'https://cdn.cropguide.io/l.js';
d.head.append(s);
})(window, document);
</script>
<?php
}
}
add_action('admin_head', 'cropguide_scripts');
?>
Load CropGuide on selected pages only
If we want to load CropGuide on a subsection of pages we can add the is_page function to the script in the functions.php file.
<?php
// The slugs of the pages we want to allow, this array
// can also contain page Id's and page titles.
$allowed_pages = array('contact', 'profile');
function cropguide_scripts() {
// Exit if current page isn't in allowed pages array
if (!is_page($allowed_pages)) return;
?>
<script>
(function (w, d) {
w.$cropguide = ['GFFFYQ'];
var s = d.createElement('script');
s.async = true;
s.src = 'https://cdn.cropguide.io/l.js';
d.head.append(s);
})(window, document);
</script>
<?php
}
add_action('wp_head', 'cropguide_scripts');
?>
The CropGuide script will now only load if the page slug matches the contact or profile.
That's it! CropGuide will now load and transform images when they're added to a file upload field on your WordPress page.
You can adjust the behavior of CropGuide in the control panel for your domain, or you can set custom instructions per field.
Please feel free to reach out to us if you have any questions.
Related content
- Crop PAN Card Photos Before Upload on WordPress
- Crop Cédula Photos Before Upload on WordPress
- Crop Identity Card Photos Before Upload on WordPress
- Crop Aadhaar Card Photos Before Upload on WordPress
- Crop Passport Document Photos Before Upload on WordPress
- Crop Circular Profile Pictures on WordPress
- Convert HEIC/HEIF to JPEG Before Upload on WordPress
- Compress User Images Before Upload on WordPress
Our photo editing technology is trusted by amazing companies
Frequently Asked Questions
-
Can I add an image cropper to my WordPress site for free?
Yes. CropGuide’s free plan lets you add image cropping to one existing file upload field, with up to 100 edits per month and no credit card required. Follow the WordPress setup steps or compare plans if you need more fields or features.
-
Do I need to replace my WordPress form to add image cropping?
No. CropGuide enhances existing file upload fields, so you can keep your form and its upload destination. See the WordPress setup steps.
-
Can users crop images in WordPress forms and admin uploads?
Yes. CropGuide can enhance file upload fields on front-end pages or in the WordPress admin. Where you add the script determines which pages load the editor.
-
Can I add image cropping only to certain WordPress pages or user roles?
Yes. You can conditionally load the CropGuide script using WordPress page or user-role checks, as shown in this installation guide.