Web Development & Design

optimise website via functions.php file

optimise website via functions.php file: specific guidance on scope and assumptions, with practical limits, trade-offs and checks for readers comparing...

Wordpress-Functions.Php-file

Optimise Your Website via Functions.php File

WordPress Functions.php File

A better way to approach optimise website via functions.php file is to start with the real-world context rather than a generic opening. This post keeps the focus on scope, assumptions, trade-offs, and the practical decision the reader is trying to make.

Enqueue Scripts and Styles Properly

Use

wp_enqueue_script()

and

wp_enqueue_style()

to load JavaScript and CSS files efficiently. Properly enqueued scripts reduce page load times and prevent conflicts.

function enqueue_custom_scripts() { wp_enqueue_script( 'custom-script', get_template_directory_uri() . '/patrick_wilson_cms_js/custom.js', array('jquery'), '1.0', true ); wp_enqueue_style('custom-style', get_stylesheet_uri()); } add_action('wp_enqueue_scripts', 'enqueue_custom_scripts');

Enable Gzip Compression

Gzip compression reduces file sizes sent from the server to the browser, improving page load speed.

function enable_gzip_compression() { if (function_exists('ob_gzhandler')) { ob_start('ob_gzhandler'); } } add_action('init', 'enable_gzip_compression');

Optimise Images

Automatically compress and serve optimised images using plugins like Smush or by adding custom code. Ensure compression does not compromise image quality.

Implement Caching

Caching stores static content to reduce server load and speed up page delivery. Use caching plugins such as W3 Total Cache or WP Super Cache, or implement custom caching solutions via code.

Optimise Database Queries

Reduce the number of database queries and optimise existing ones for better performance. Use the

$wpdb

object and ensure proper indexing in your queries.

Disable Emojis and Embeds

Remove unnecessary functionality like emojis and oEmbeds to improve load times. Add the following code to

functions.php

:

function disable_emojis() { remove_action('wp_head', 'print_emoji_detection_script', 7); remove_action('admin_print_scripts', 'print_emoji_detection_script'); remove_action('wp_print_styles', 'print_emoji_styles'); remove_action('admin_print_styles', 'print_emoji_styles'); remove_filter('the_content_feed', 'wp_staticize_emoji'); remove_filter('comment_text_rss', 'wp_staticize_emoji'); remove_filter('wp_mail', 'wp_staticize_emoji_for_email'); } add_action('init', 'disable_emojis');

Limit Post Revisions

WordPress stores revisions for posts, which can increase database size. Limit the number of revisions or disable them entirely:

define('WP_POST_REVISIONS', 5); // Limit to 5 revisions

Remove Query Strings from Static Resources

Query strings in URLs can prevent proper caching. Remove them using:

if (!function_exists('remove_query_strings')) { function remove_query_strings() { // Function code here } } add_action('init', 'remove_query_strings');

Handling “Cannot Redeclare” Errors

This error occurs when a function is declared multiple times. For example, if

remove_query_strings()

appears in both parent and child themes, it causes a redeclaration error. To fix:

  • Locate Duplicate Declarations: Check both parent and child

    functions.php

    files and external includes.
  • Merge or Remove Duplicates: Keep only one declaration, preferably in the child theme.
  • Use Conditional Checks: Wrap functions with

    function_exists()

    to prevent redeclaration:

if (!function_exists('remove_query_strings')) { function remove_query_strings() { // Function code here } }

  • Clear Cache: After changes, clear browser cache and caching plugins, then reload the site.

Always back up your

functions.php

file before making changes and test on a staging or local environment to prevent site errors or downtime.

Extra context before acting on this topic

optimise website via functions.php file needs enough practical context to stand on its own. Before acting, readers should check the cost, effort, limits, and local suitability behind the idea rather than relying on a broad summary.

Pfine

Pfine

Verified

Digital Entreprenuer

Patrick Wilson is a passionate fine artist, digital creator, blogger, and online entrepreneur dedicated to blending creativity, technology, and impactful storytelling. Through visually expressive artwork, insightful articles, and innovative digital projects, he explores topics ranging from art and culture to web development, online business, technology, lifestyle, and modern digital trends.

As the founder of AllTopicsHub, Patrick creates educational and engaging content designed to inspire creativity, encourage learning, and empower audiences through practical knowledge and artistic expression. His work combines traditional artistic vision with contemporary digital innovation, delivering unique experiences across visual media, blogging, and web-based platforms.

With a strong passion for creative excellence, entrepreneurship, and digital publishing, Patrick Wilson continues to build meaningful online experiences that connect art, information, technology, and community under one evolving creative brand.

WebsiteNyeri, Kenya

Find this information worthwhile?

If my research or technical insights have helped you flourish in the digital world, consider supporting the continued development of this platform.

Support via PayPal

Contribution to: Pfine

Keep exploring

Explore more practical guides on AllTopicsHub

Discover more trustworthy tutorials, explainers, and practical articles across business, technology, lifestyle, and everyday topics.

Browse all topicsMore in Web Development & Design

Related reading

Explore more in Web Development & Design

Web Development & Design

How Your Relevant Insights Can Earn a Valuable Backlink

How Your Relevant Insights Can Earn a Valuable Backlink needs a practical lens: what to inspect, what to…

Web Development & Design

Easy SEO Link Building

Martins Free and Easy SEO link building : Boost Your Website's SEO with Genuine Backlinks Easy SEO Link…

Web Development & Design

Domain Authority (DA) vs Domain Rating (DR) what's the difference?

DA might be more useful for assessing the overall SEO health of a site, including technical SEO, content…

✦✦✦✦✦✦✦✦✦✦✦✦✦✦