forked from laras126/scotty-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
executable file
·109 lines (79 loc) · 3.42 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
<?php
// If the Timber plugin isn't activated, print a notice in the admin.
if ( ! class_exists( 'Timber' ) ) {
add_action( 'admin_notices', function() {
echo '<div class="error"><p>Timber not activated. Make sure you activate the plugin in <a href="' . esc_url( admin_url( 'plugins.php#timber' ) ) . '">' . esc_url( admin_url( 'plugins.php' ) ) . '</a></p></div>';
} );
return;
}
// Create our version of the TimberSite object
class StarterSite extends TimberSite {
// This function applies some fundamental WordPress setup, as well as our functions to include custom post types and taxonomies.
function __construct() {
add_theme_support( 'post-formats',
array(
'image',
'gallery',
'video',
'quote',
'link'
) );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'menus' );
add_filter( 'timber_context', array( $this, 'add_to_context' ) );
add_filter( 'get_twig', array( $this, 'add_to_twig' ) );
add_action( 'init', array( $this, 'register_post_types' ) );
add_action( 'init', array( $this, 'register_taxonomies' ) );
add_action( 'init', array( $this, 'register_menus' ) );
add_action( 'init', array( $this, 'register_widgets' ) );
parent::__construct();
}
// Abstracting long chunks of code.
// The following included files only need to contain the arguments and register_whatever functions. They are applied to WordPress in these functions that are hooked to init above.
// The point of having separate files is solely to save space in this file. Think of them as a standard PHP include or require.
function register_post_types(){
require('lib/custom-types.php');
}
function register_taxonomies(){
require('lib/taxonomies.php');
}
function register_menus(){
require('lib/menus.php');
}
function register_widgets(){
require('lib/widgets.php');
}
// Access data site-wide.
// This function adds data to the global context of your site. In less-jargon-y terms, any values in this function are available on any view of your website. Anything that occurs on every page should be added here.
function add_to_context( $context ) {
// Our menu occurs on every page, so we add it to the global context.
$context['menu'] = new TimberMenu();
// This 'site' context below allows you to access main site information like the site title or description.
$context['site'] = $this;
return $context;
}
// Here you can add your own fuctions to Twig. Don't worry about this section if you don't come across a need for it.
// See more here: http://twig.sensiolabs.org/doc/advanced.html
function add_to_twig( $twig ) {
$twig->addExtension( new Twig_Extension_StringLoader() );
$twig->addFilter( 'myfoo', new Twig_Filter_Function( 'myfoo' ) );
return $twig;
}
}
new StarterSite();
/*
*
* My Functions (not from Timber)
*
*/
// Enqueue scripts
function my_scripts() {
// Use jQuery from a CDN
wp_deregister_script('jquery');
wp_register_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js', array(), null, true);
// Enqueue our stylesheet and JS file with a jQuery dependency.
// Note that we aren't using WordPress' default style.css, and instead enqueueing the file of compiled Sass.
wp_enqueue_style( 'my-styles', get_template_directory_uri() . '/assets/css/main.css', 1.0);
wp_enqueue_script( 'my-js', get_template_directory_uri() . '/assets/js/main.js', array('jquery'), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'my_scripts' );