-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
executable file
·125 lines (88 loc) · 3.48 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* Fargio Child functions and definitions
*
* Bellow you will find several ways to tackle the enqueue of static resources/files
* It depends on the amount of customization you want to do
* If you either wish to simply overwrite/add some CSS rules or JS code
* Or if you want to replace certain files from the parent with your own (like style.css or main.js)
*
* @package FargoChild
*/
/**
* Setup Fargo Child Theme's textdomain.
*
* Declare textdomain for this child theme.
* Translations can be filed in the /languages/ directory.
*/
function fargo_child_theme_setup() {
load_child_theme_textdomain( 'fargo-child-theme', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'fargo_child_theme_setup' );
/**
*
* 1. Add a Child Theme "style.css" file
* ----------------------------------------------------------------------------
*
* If you want to add static resources files from the child theme, use the
* example function written below.
*
*/
function fargo_child_enqueue_styles() {
$theme = wp_get_theme();
$parent = $theme->parent();
if ( is_rtl() ) {
wp_enqueue_style( 'fargo-rtl-style', get_template_directory_uri() . '/rtl.css', array(), $parent->get( 'Version' ) );
} else {
wp_enqueue_style( 'fargo-main-style', get_template_directory_uri() . '/style.css', array(), $parent->get( 'Version' ) );
}
// Here we are adding the child style.css while still retaining
// all of the parents assets (style.css, JS files, etc)
wp_enqueue_style( 'fargo-child-style',
get_stylesheet_directory_uri() . '/style.css',
array('fargo-main-style'), //make sure the the child's style.css comes after the parents so you can overwrite rules
$parent->get( 'Version' )
);
}
add_action( 'wp_enqueue_scripts', 'fargo_child_enqueue_styles' );
/**
*
* 2. Overwrite Static Resources (eg. style.css or main.js)
* ----------------------------------------------------------------------------
*
* If you want to overwrite static resources files from the parent theme
* and use only the ones from the Child Theme, this is the way to do it.
*
*/
/*
function fargo_child_overwrite_files() {
// 1. The "main.js" file
//
// Let's assume you want to completely overwrite the "main.js" file from the parent
// First you will have to make sure the parent's file is not loaded
// See the parent's function.php -> the fargo_scripts_styles() function
// for details like resources names
wp_dequeue_script( 'fargo-main-scripts' );
// We will add the main.js from the child theme (located in assets/js/main.js)
// with the same dependecies as the main.js in the parent
// This is not required, but I assume you are not modifying that much :)
wp_enqueue_script( 'fargo-child-scripts',
get_stylesheet_directory_uri() . '/assets/js/main.js',
array( 'jquery' ),
'1.0.0', true );
// 2. The "style.css" file
//
// First, remove the parent style files
// see the parent's function.php -> the hive_scripts_styles() function for details like resources names
wp_dequeue_style( 'fargo-main-style' );
// Now you can add your own, modified version of the "style.css" file
wp_enqueue_style( 'fargo-child-style',
get_stylesheet_directory_uri() . '/style.css'
);
}
// Load the files from the function mentioned above:
add_action( 'wp_enqueue_scripts', 'fargo_child_overwrite_files', 11 );
// Notes:
// The 11 priority parameter is need so we do this after the function in the parent so there is something to dequeue
// The default priority of any action is 10
*/