Skip to content

Commit

Permalink
Update customizer settings
Browse files Browse the repository at this point in the history
  • Loading branch information
rami-elementor committed Jul 25, 2023
1 parent 032531b commit 6399526
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 39 deletions.
66 changes: 52 additions & 14 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,29 @@ function hello_elementor_content_width() {
}
add_action( 'after_setup_theme', 'hello_elementor_content_width', 0 );

if ( ! function_exists( 'hello_elementor_add_description_meta_tag' ) ) {
/**
* Add description meta tag with excerpt text.
*
* @return void
*/
function hello_elementor_add_description_meta_tag() {
if ( apply_filters( 'hello_elementor_description_meta_tag', true ) ) {
if ( ! is_singular() ) {
return;
}

$post = get_queried_object();
if ( empty( $post->post_excerpt ) ) {
return;
}

echo '<meta name="description" content="' . esc_attr( wp_strip_all_tags( $post->post_excerpt ) ) . '">' . "\n";
}
}
}
add_action( 'wp_head', 'hello_elementor_add_description_meta_tag' );

if ( is_admin() ) {
require get_template_directory() . '/includes/admin-functions.php';
}
Expand Down Expand Up @@ -189,7 +212,7 @@ function hello_register_customizer_functions() {
* @return bool
*/
function hello_elementor_check_hide_title( $val ) {
if ( '1' === get_option( 'hello_elementor_disable_page_title' ) ) {
if ( 'off' === get_theme_mod( 'page_title' ) ) {
$val = false;
}

Expand All @@ -205,30 +228,45 @@ function hello_elementor_check_hide_title( $val ) {
}
add_filter( 'hello_elementor_page_title', 'hello_elementor_check_hide_title' );

if ( ! function_exists( 'hello_elementor_add_description_meta_tag' ) ) {
if ( ! function_exists( 'hello_elementor_check_skip_link' ) ) {
/**
* Add description meta tag with excerpt text.
* Check whether to add a link to main content for screen-reader users.
*
* @return void
* @param bool $val default value.
*
* @return bool
*/
function hello_elementor_add_description_meta_tag() {
if ( '1' === get_option( 'hello_elementor_disable_description_meta_tag' ) ) {
return;
function hello_elementor_check_skip_link( $val ) {
if ( 'off' === get_theme_mod( 'skip_link' ) ) {
$val = false;
}

if ( ! is_singular() ) {
return;
return $val;
}
}
add_filter( 'hello_elementor_enable_skip_link', 'hello_elementor_check_skip_link' );

if ( ! function_exists( 'hello_elementor_check_description_meta_tag' ) ) {
/**
* Check whether to add the description meta tag.
*
* @param bool $val default value.
*
* @return bool
*/
function hello_elementor_check_description_meta_tag( $val ) {
if ( ! get_theme_mod( 'description_meta_tag' ) ) {
$val = false;
}

$post = get_queried_object();
if ( empty( $post->post_excerpt ) ) {
return;
if ( 'off' === get_theme_mod( 'description_meta_tag' ) ) {
$val = false;
}

echo '<meta name="description" content="' . esc_attr( wp_strip_all_tags( $post->post_excerpt ) ) . '">' . "\n";
return $val;
}
}
add_action( 'wp_head', 'hello_elementor_add_description_meta_tag' );
add_filter( 'hello_elementor_description_meta_tag', 'hello_elementor_check_description_meta_tag' );

/**
* BC:
Expand Down
79 changes: 54 additions & 25 deletions includes/customizer-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,63 +20,96 @@ function hello_customizer_register( $wp_customize ) {
'hello_elementor',
[
'title' => esc_html__( 'Theme Settings', 'hello-elementor' ),
'description' => esc_html__( 'Customize your Hello Elementor theme settings.', 'hello-elementor' ),
'description' => esc_html__( 'Customize your Hello theme settings.', 'hello-elementor' ),
'capability' => 'edit_theme_options',
]
);

// Description meta tag

$wp_customize->add_setting(
'hello_elementor_disable_description_meta_tag',
'description_meta_tag',
[
'type' => 'option',
'type' => 'theme_mod',
'default' => 'off',
'transport'=>'postMessage',
'capability' => 'edit_theme_options',
'default' => '',
'sanitize_callback' => 'hello_customizer_sanitize_checkbox',
]
);

$wp_customize->add_control(
'hello_elementor_disable_description_meta_tag',
'description_meta_tag',
[
'label' => esc_html__( 'Disable description meta tag', 'hello-elementor' ),
'type' => 'checkbox',
'label' => esc_html__( 'Description meta tag', 'hello-elementor' ),
'description' => esc_html__( 'Meta tag in the `<head>` containing the post/page excerpt.', 'hello-elementor' ),
'type' => 'radio',
'choices' => [
'on' => esc_html__( 'Enable', 'hello-elementor' ),
'off' => esc_html__( 'Disable', 'hello-elementor' ),
],
'section' => 'hello_elementor',
'settings' => 'hello_elementor_disable_description_meta_tag',
'settings' => 'description_meta_tag',
]
);

// Skip Links

$wp_customize->add_setting(
'skip_link',
[
'type' => 'theme_mod',
'default' => 'on',
'transport'=>'postMessage',
'capability' => 'edit_theme_options',
]
);

$wp_customize->add_control(
'skip_link',
[
'label' => esc_html__( 'Skip link', 'hello-elementor' ),
'description' => esc_html__( 'A link to the main content used by screen-reader users.', 'hello-elementor' ),
'type' => 'radio',
'choices' => [
'on' => esc_html__( 'Enable', 'hello-elementor' ),
'off' => esc_html__( 'Disable', 'hello-elementor' ),
],
'section' => 'hello_elementor',
'settings' => 'skip_link',
]
);

// Page titles

$wp_customize->add_setting(
'hello_elementor_disable_page_title',
'page_title',
[
'type' => 'option',
'type' => 'theme_mod',
'default' => 'on',
'capability' => 'edit_theme_options',
'default' => '',
'sanitize_callback' => 'hello_customizer_sanitize_checkbox',
]
);

$wp_customize->add_control(
'hello_elementor_disable_page_title',
'page_title',
[
'label' => esc_html__( 'Disable page title', 'hello-elementor' ),
'type' => 'checkbox',
'label' => esc_html__( 'Page title', 'hello-elementor' ),
'description' => esc_html__( 'A section above the content contaning the `<h1>` heading of the page.', 'hello-elementor' ),
'type' => 'radio',
'choices' => [
'on' => esc_html__( 'Enable', 'hello-elementor' ),
'off' => esc_html__( 'Disable', 'hello-elementor' ),
],
'section' => 'hello_elementor',
'settings' => 'hello_elementor_disable_page_title',
'settings' => 'page_title',
]
);

// Header & Footer promotion

$wp_customize->add_setting(
'hello_elementor_header_footer',
[
'sanitize_callback' => false,
'transport' => 'refresh',
]
[]
);

$wp_customize->add_control(
Expand All @@ -91,10 +124,6 @@ function hello_customizer_register( $wp_customize ) {
);
}

function hello_customizer_sanitize_checkbox( $checked ) {
return '1' == $checked ? '1' : '';
}

/**
* Enqueue Customiser CSS
*
Expand Down

0 comments on commit 6399526

Please sign in to comment.