5 things you can do in WordPress without plugins

Bogdan Bendziukov
4 min readMay 13, 2023

--

As for 13th of May the year 2023, there are 60414 plugins in the WordPress repository. That’s a massive number! Some of them are complex, some of them simple but effective. But when it comes to a couple of code strings there’s no need to install a whole plugin for it. Just paste the code into your functions.php file and get the same result. Plus you won’t get problems with an enormous number of plugins and reduce the load on your site.

Photo by Maksym Diachenko on Unsplash

Switch back to the Classic Editor

From the WordPress version of 5.0 the Gutenberg Page Builder was merged into WordPress. It replaced the good old Tiny MCE Editor, more famous as the Classic Editor. I didn’t like the Gutenberg from the start, TBH. Some people still remain loyal to the Classic Editor. So to switch to the Classic Editor from the Gutenberg jus use this one line of code:

add_filter('use_block_editor_for_post', '__return_false', 10);

Restore the Classic Widgets

Not only the page editor was affected by Gutenberg, but widgets too. To restore the Classic Widgets use this code (remember to change the theme_prefix part to your theme’s slug):

add_action( 'after_setup_theme', 'theme_prefix_theme_support' );
function theme_prefix_theme_support() {
remove_theme_support( 'widgets-block-editor' );
}

Allow SVG upload

By default WordPress does not allow users to upload SVG images into the Media Library.

This is because SVGs aren’t a typical image format like JPEGs or PNGs. The SVG file itself is a code to define lines, curves, colours, etc. And because anything using code can be manipulated for malicious purposes, WordPress prevents users from uploading SVG files.

This is good and thank you WordPress again for caring about our websites’ security, but we need that darn logo to be in SVG!

add_filter( 'wp_check_filetype_and_ext', 'theme_prefix_allow_svg', 10, 4 );
function theme_prefix_allow_svg( $data, $file, $filename, $mimes ) {
global $wp_version;
if ( $wp_version !== '4.7.1' ) {
return $data;
}
$filetype = wp_check_filetype( $filename, $mimes );
return [
'ext' => $filetype['ext'],
'type' => $filetype['type'],
'proper_filename' => $data['proper_filename']
];
}

add_filter( 'upload_mimes', 'theme_prefix_mime_types' );
function theme_prefix_mime_types ( $mimes ){
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}

add_action( 'admin_head', 'theme_prefix_fix_svg');
function theme_prefix_fix_svg() {
echo '<style type="text/css">
.attachment-266x266, .thumbnail img {
width: 100% !important;
height: auto !important;
}
</style>';
}

Mind to change the theme_prefix part!

Stretch Gutenberg to full width

If you’re using the Gutenberg Builder and struggle with too narrow width of it, use this code to stretch it to the full screen width:

add_action('admin_head', 'theme_prefix_full_width_gutenberg');
function theme_prefix_full_width_gutenberg() {
echo '<style>
body.gutenberg-editor-page .editor-post-title__block, body.gutenberg-editor-page .editor-default-block-appender, body.gutenberg-editor-page .editor-block-list__block {
max-width: none !important;
}
.block-editor__container .wp-block {
max-width: none !important;
}
/*code editor*/
.edit-post-text-editor__body {
max-width: none !important;
margin-left: 2%;
margin-right: 2%;
}
</style>';
}

It will switch from this:

Default width of the Gutenberg Editor

…to this:

Full width of the Gutenberg Editor

Redirect to another page

If you need to set up a redirect from one page to another, here’s how you can achieve this. Let’s say you want to redirect a page with the url https://yoursite.com/my-old-page to the url with the slug https://yoursite.com/my-new-page:

add_action('template_redirect', 'theme_prefix_redirect_page');
function theme_prefix_redirect_page(){
if ( is_page('my-old-page') ){
wp_redirect( home_url('/my-new-page'), 301 );
}
}

Of course, if you’re planning to have many redirects it’s better to use a plugin, so you can comfortably navigate and handle through your redirects.

That’s all for today folks, I will think about more code snippets to use instead of plugins. Not at the expense of convenience, of course 😉.

Thanks for reading!
Stay safe and peace to you!

--

--

Bogdan Bendziukov

I'm a web developer from Kyiv 💛💙. A WordPress enthusiast for 10 years. Writing tips and thoughts from my dev experience .