πŸ’›Functions.php

WP Rig Toolkit offers numerous customization options. Some of these can be turned into components, while others are relatively small. During your project development, you may need to store your WP customizations somewhere. Writing a plugin may not always be necessary if your customization is small and/or cannot be separated from the theme.

WP Rig Toolkit offers many customizations, some of which can be transformed into components and others which are small. When working on a project, it is often necessary to store functions and customizations somewhere in WordPress.

While it is not always necessary to create a plugin for small customizations that cannot be detached from the theme, it is important to note that a large and complex functions.php file may not be the best option for a smooth development process. To address this, we have separated functions.php into multiple partial .php files located in the functions folder in the root directory.

πŸ“„ functions.php

Default content
<?php
/**
 * Main Theme Functions and Definitions
 *
 * This file contains the core functions and hooks necessary to power the WP Rig theme.
 *
 * @link https://developer.wordpress.org/themes/basics/theme-functions/
 * @package wp_rig
 */

/**
 * WP Rig Init.
 */
require get_template_directory() . '/functions/_functions-rig-init.php';


/**
 * WordPress Customizations.
 */

define( 'STOP_ADDING_P_TAGS', true ); // Stop WordPress from adding <p> tags.
define( 'DISABLE_VISUAL_EDITOR', false ); // Disable Visual editor completely.
define( 'DISABLE_VISUAL_EDITOR_ADMINS_ONLY', false ); // Disable Visual editor only for admins.
define( 'HEADERS_CLEAN_ARCHIVE_CATEGORY', true ); // Clean page headers from "Archive:" and "Category:".
define( 'ADD_PAGE_EXCERPTS_SUPPORT', true ); // Add Post Excerpts Support for Pages.
define( 'DISABLE_COMMENTS', true ); // Disable Comments on the site.
define( 'DISABLE_WP_ALL_THUMBNAILS_GENERATING', false ); // Completely disable WordPress Image Resizing. You may decide that it's not needed in your project.
define( 'DISABLE_WP_DEFAULT_THUMBNAILS_SIZES', true ); // Disable only certain WordPress thumbnails sizes. Customize it if needed.
define( 'DISABLE_WP_IMAGE_SCALING', false ); // Disable WordPress Image Scaling. By default WP limits height for you images to 256px. This filter removes it.
define( 'ADD_CUSTOM_HEADER_SUPPORT', true ); // Register shortcode for custom h1 heading for post and pages and automatically render if custom h1 is set.

/**
 * Plugins Customizations.
 */

define( 'CF7_DISABLE_DEFAULT_LOADING_JS_CSS', true ); // Contact Form 7: Disable automatic loading of CF7 .js and .css.
define( 'CF7_CLEAN_MARKUP', true ); // Contact Form 7: Remove <p> and <br> from Contact Form 7.
define( 'YOAST_BREADCRUMBS_ADD_SCHEMA', true ); // YoastSEO: Add Schema to YoastSEO breadcrumb.
define( 'YOAST_BREADCRUMBS_CLEAN_SPAN', true ); // YoastSEO: Filter the output of Yoast breadcrumbs to remove <span> tags added by the plugin.
define( 'YOAST_SEARCHACTION_JSON_DISABLE', true ); // YoastSEO: Remove SearchAction from yoast-schema-graph JSON structured data. If you don't have a working search on your site (for example you have a generated a static site from your WP).
define( 'ELEMENTOR_REMOVE_STANDART_FONTS', true ); // Elementor: Remove default fonts from loading.

/**
 * Optimization and code cleaning.
 */

define( 'DEFER_ALL_SCRIPTS', true ); // Defer all scripts (exl. jquery and wp-admin scripts).
define( 'DISABLE_SCRIPTS_STYLES_VERSIONS', false ); // Disable versions in the end of scripts and styles links.
define( 'DISABLE_TYPE_ATTRIBUTES', true ); // Disable type attributes from scripts and styles.
define( 'DISABLE_DEFAULT_BLOCK_STYLES', true ); // Remove default block styles.
define( 'DISABLE_WP_POLYFILL', true ); // Remove WP Polyfill js.


/**
 * Components settings.
 */

/**
 * Define Daynight default mode.
 *
 * Define your original version of website.
 * Acceptaple values: 'day', 'night'.
 *
 * https://docs.wprig.org/coming-soon
 */

define( 'WP_RIG_DAYNIGHT_DEFAULT_MODE', 'day' );


/**
 * ============
 * * Basic Customizations
 *
 * Must-have and not configurable through contsants above.
 * ============
 */

// Menu functions (registering new menus, menu walkers).
require get_template_directory() . '/functions/_functions-menu.php';


/**
 * ============
 * * Registeting new types
 *
 * Register new thumbnails size, shortcodes etc.
 * ============
 */

// Register new thumbnail sizes.
require get_template_directory() . '/functions/_functions-custom-thumbnails.php';

// Register new ACF fields.
if ( class_exists( 'ACF' ) ) {
	require get_template_directory() . '/functions/_functions-acf-fields.php';
}

// Register custom actions.
require get_template_directory() . '/functions/_functions-custom-actions-filters.php';

// Register custom shortcodes.
require get_template_directory() . '/functions/_functions-custom-shortcodes.php';

// Enqueue/dequeue custom files.
require get_template_directory() . '/functions/_functions-custom-files.php';


/**
 * ============
 * * WordPress Customizations
 * ============
 */
require get_template_directory() . '/functions/_functions-wp-customizations.php';


/**
 * ============
 * * Plugins Customizations
 * ============
 */
require get_template_directory() . '/functions/_functions-plugins.php';


/**
 * ============
 * * Optimization and Cleaning
 * ============
 */
require get_template_directory() . '/functions/_functions-optimization.php';

All the function are placed in partials files in πŸ“‚ /functions/ for better clarity and easier management.

πŸ“„ _functions-acf-fields.php

Sometimes you may want to create ACF fields automatically. WP Rig Toolkit also includes the creation of a custom_h1 field for use in core SEO optimizations. To learn more, read about the heading structure and custom headings.

Default content
<?php
/**
 * Auto creation of ACF fields functions
 *
 * Sometimes you want to register ACF fields automatically so you can register them here
 *
 * @link https://docs.wprig.org/coming-soon
 *
 * @package wp_rig
 */

// Check if ACF exists.
if ( class_exists( 'ACF' ) ) {

	/**
	 * Register field for custom H1.
	 *
	 * Adds a custom field for overriding the default H1 tag.
	 */
	function add_custom_acf_post_and_page_options() {

		acf_add_local_field_group(
			array(
				'key'      => 'group_posts_and_pages_options',
				'title'    => 'Post & Pages Options',
				'fields'   => array(
					array(
						'key'          => 'field_custom_h1',
						'label'        => 'Custom H1',
						'name'         => 'custom_h1',
						'type'         => 'text',
						'instructions' => 'Fill this field if you want to override the default H1 tag (usually post or page name). Max length is 80 symbols but for SEO purposes it\'s better to use headers under 60-70.',
						'maxlength'	   => '80',
					),
				),
				'location' => array(
					array(
						array(
							'param'	   => 'post_type',
							'operator' => '==',
							'value'	   => 'page',
						),
					),
					array(
						array(
							'param'    => 'post_type',
							'operator' => '==',
							'value'    => 'post',
						),
					),
				),
			)
		);
	}

	add_action( 'acf/init', 'add_custom_acf_post_and_page_options' );
}

πŸ“„ _functions-custom-actions-filters.php

A place for custom actions and filters.

Default content

πŸ“„ _functions-custom-files.php

By default, it contains the enqueuing of global.min.js and elements-configuration.min.js. It can be useful when you want to enqueue or dequeue your own files using WP functions.

Default content

πŸ“„ _functions-custom-shortcodes.php

If you don't want to create a plugin for your shortcodes, you can place them here.

Default content

A place for registering custom thumbnail sizes in WordPress.

πŸ“„ _functions-menu.php

In this file, you can register new menus and customize them. By default, there are already some functions available

Default content

πŸ“„ _functions-optimization.php

Various optimizations aimed at providing cleaner code and faster loading speed.

Default content

πŸ“„ _functions-plugins.php

Various optional helper functions and extensions for popular plugins.

Default content

πŸ“„ _functions-rig-init.php

Initialization section of functions.php. You shouldn't touch it.

πŸ“„ _functions-wp-customizations.php

Customization which affect WordPress engine.

Default content

Last updated