Created
September 1, 2021 12:08
-
-
Save yratof/96cc8b646cf2dae39e93d24d56471fbf to your computer and use it in GitHub Desktop.
Add scripts to customizer for wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Customiser script */ | |
add_action( 'customize_register', 'custom_editor' ); | |
function custom_editor( $wp_customize ) { | |
// Analytics section | |
$wp_customize->add_section('analytics_section', array( | |
'title' => __( 'Analytics', 'tuesday' ), | |
'description' => __( 'Enable tracking and analytics by placing your script tags in the correct location. <small><strong>Note:</strong> All scripts must be self-containing <script></script>, otherwise they will just print the code onto the website.</small>', 'tuesday' ), | |
'priority' => 160, | |
'transport' => 'postMessage', | |
)); | |
// head scripts | |
$wp_customize->add_setting('analytics_head', array( | |
'default' => '', | |
'capability' => 'edit_theme_options', | |
)); | |
$wp_customize->add_control('analytics_head', array( | |
'label' => __( 'Scripts in the <head>', 'tuesday' ), | |
'description' => __( 'Place script tags in the <head>', 'tuesday' ), | |
'type' => 'textarea', | |
'input_attrs' => [ | |
'data-name' => __( 'Head', 'tuesday' ), | |
'placeholder' => __( '<script>google.analytic.manager...', 'tuesday' ), | |
], | |
'section' => 'analytics_section', | |
'settings' => 'analytics_head', | |
)); | |
$wp_customize->add_setting('analytics_footer', array( | |
'default' => '', | |
'capability' => 'edit_theme_options', | |
)); | |
$wp_customize->add_control('analytics_footer', array( | |
'label' => __( 'Scripts in the <footer>', 'tuesday' ), | |
'description' => __( 'Place scripts in the footer', 'tuesday' ), | |
'type' => 'textarea', | |
'input_attrs' => [ | |
'data-name' => __( 'Footer', 'tuesday' ), | |
'placeholder' => __( '<script>RUM.manager...', 'tuesday' ), | |
], | |
'section' => 'analytics_section', | |
'settings' => 'analytics_footer', | |
)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment