Last active
November 1, 2017 05:29
-
-
Save patric-boehner/9eea5d6154d251f3746c0070862a5e5c to your computer and use it in GitHub Desktop.
Genesis Custom Theme Settings for Site Tagline
This file contains hidden or 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 | |
| /** | |
| * Custom Genesis Theme Settings | |
| * At the moment this doesn't output anything if the default tagline is empty. | |
| * | |
| * @package Child Theme | |
| * @author Patrick Boehner | |
| * @copyright Copyright (c) 2017, Patrick Boehner | |
| * @license GPL-2.0+ | |
| * | |
| * Inspired by Bill Erickson's example. | |
| * @link http://www.billerickson.net/genesis-theme-options/ | |
| */ | |
| //* Security Updates | |
| //******************************* | |
| //* Block Direct Acess | |
| if( !defined( 'ABSPATH' ) ) exit; | |
| //* Multi-lin Site Description | |
| //******************************* | |
| // Register defaults | |
| add_filter( 'genesis_theme_settings_defaults', 'pb_custom_site_description_defaults' ); | |
| function pb_custom_site_description_defaults( $defaults ) { | |
| $defaults['pb_site_description'] = ''; | |
| $defaults['pb_sub_description'] = ''; | |
| return $defaults; | |
| } | |
| // Sanitization | |
| add_action( 'genesis_settings_sanitizer_init', 'pb_sanitization_filters' ); | |
| function pb_sanitization_filters() { | |
| genesis_add_option_filter( | |
| 'no_html', | |
| GENESIS_SETTINGS_FIELD, | |
| array( | |
| 'pb_site_description', | |
| 'pb_sub_description', | |
| ) ); | |
| } | |
| // Register metabox | |
| add_action('genesis_theme_settings_metaboxes', 'pb_site_description_settings_box'); | |
| function pb_site_description_settings_box( $_genesis_theme_settings_pagehook ) { | |
| add_meta_box( 'pb-genesis-settings', __( 'Custom Site Description / Tagline', 'pb' ), 'pb_site_description_box', $_genesis_theme_settings_pagehook, 'main', 'high' ); | |
| } | |
| // Create metabox | |
| function pb_site_description_box() { | |
| ?> | |
| <p><span class="description"><?php echo 'Create a multi-line site description that shows in the header of the website and replaces <a href="options-general.php">the default site tagline</a>.'; ?></span></p> | |
| <table class="form-table"> | |
| <tbody> | |
| <tr valign="top"> | |
| <th scope="row"> | |
| <label><?php _e( 'Description:', 'core-functionality' ); ?></label> | |
| </th> | |
| <td> | |
| <p> | |
| <input type="text" id="pb_site_description" class="regular-text" name="<?php echo GENESIS_SETTINGS_FIELD; ?>[pb_site_description]" value="<?php echo esc_html( genesis_get_option('pb_site_description') ); ?>"> | |
| </p> | |
| </td> | |
| </tr> | |
| <tr valign="top"> | |
| <th scope="row"> | |
| <label><?php _e( 'Sub-Description:', 'core-functionality' ); ?></label> | |
| </th> | |
| <td> | |
| <p> | |
| <input type="text" id="pb_sub_description" class="regular-text" name="<?php echo GENESIS_SETTINGS_FIELD; ?>[pb_sub_description]" value="<?php echo esc_html( genesis_get_option('pb_sub_description') ); ?>"> | |
| </p> | |
| </td> | |
| </tr> | |
| </tbody> | |
| </table> | |
| <?php | |
| } | |
| // Customize the footer credits text | |
| add_filter('genesis_seo_description', 'pb_site_description_text', 10, 3); | |
| function pb_site_description_text( $description, $inside, $wrap ) { | |
| // Setup Variable recalls | |
| $custom_description = esc_html( genesis_get_option( 'pb_site_description' ) ); | |
| $custom_sub_description = esc_html( genesis_get_option( 'pb_sub_description' ) ); | |
| // If input is available add markup | |
| if ( !empty( $custom_description ) ) { | |
| $custom_description = '<span class="description">' .$custom_description. '</span></br>'; | |
| } | |
| if ( !empty( $custom_sub_description ) ) { | |
| $custom_sub_description = '<span class="sub-description">' .$custom_sub_description. '</span>'; | |
| } | |
| // Combine together | |
| $inside = $custom_description . $custom_sub_description; | |
| $output = genesis_markup( array( | |
| 'open' => sprintf( "<{$wrap} %s>", genesis_attr( 'site-description' ) ), | |
| 'close' => "</{$wrap}>", | |
| 'content' => $inside, | |
| 'context' => 'site-description', | |
| 'echo' => false, | |
| 'params' => array( | |
| 'wrap' => $wrap, | |
| ), | |
| ) ); | |
| // Return the default site description if a custom one isn't available | |
| if ( empty( $custom_description ) && empty( $custom_sub_description ) ) { | |
| return $description; | |
| } | |
| return $output; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment