Archived topic
H2 Title in Footer, Header, Top Bar and Footer Widgets
16 replies · Started by Dean on April 7, 2018
Hi Tom.
From looking at the themes general.php file, I can see that GP is setting all the widget titles to h2s.
if ( ! function_exists( 'generate_widgets_init' ) ) {
add_action( 'widgets_init', 'generate_widgets_init' );
/**
* Register widgetized area and update sidebar with default widgets
*/
function generate_widgets_init() {
$widgets = array(
'sidebar-1' => __( 'Right Sidebar', 'generatepress' ),
'sidebar-2' => __( 'Left Sidebar', 'generatepress' ),
'header' => __( 'Header', 'generatepress' ),
'footer-1' => __( 'Footer Widget 1', 'generatepress' ),
'footer-2' => __( 'Footer Widget 2', 'generatepress' ),
'footer-3' => __( 'Footer Widget 3', 'generatepress' ),
'footer-4' => __( 'Footer Widget 4', 'generatepress' ),
'footer-5' => __( 'Footer Widget 5', 'generatepress' ),
'footer-bar' => __( 'Footer Bar','generatepress' ),
'top-bar' => __( 'Top Bar','generatepress' ),
);
foreach ( $widgets as $id => $name ) {
register_sidebar( array(
'name' => $name,
'id' => $id,
'before_widget' => '<aside id="%1$s" class="widget inner-padding %2$s">',
'after_widget' => '</aside>',
'before_title' => apply_filters( 'generate_start_widget_title', '<h2 class="widget-title">' ),
'after_title' => apply_filters( 'generate_end_widget_title', '</h2>' ),
) );
}
}
}
I can also see there is a filter I can use to change these to h4s, but then I saw this topic on the forum where you suggest it is like this for accessibility reasons.
https://generatepress.com/forums/topic/footer-widget-heading-h2/
This has made hesitant to change them. Could you elaborate why you think it is better to have these set to h2s, because as far as I understand for SEO reasons they should be set to h4? Looking at Yoast and others they mostly use h4s and occasionally h3.
Would appreciate if you could provide any insight, otherwise I think I will go ahead and change them to h4s
Thank you :-).
When we had our accessibility review, that was one of the things that was suggested to us to increase accessibility of the theme. I believe it's better for screen readers.
However, if you need to switch it to an h4, I don't think it will make your site inaccessible.
Thanks for clarifying Tom :-).
No problem :)
Yes, the widget titles should definately be h4 instead of h2 for SEO.
I tried to make this change into my child theme folder /themes/childtheme/inc/general.php but it doesn't work. Only when I make the change to the /themes/generatepress/inc/general.php it will apply.
So what other changes / files I need in my child theme in order it to use that particular general.php?
You can use whatever element you want with these filters:
add_filter( 'generate_start_widget_title', 'tu_adjust_widget_title' );
function tu_adjust_widget_title() {
return '<h4 class="widget-title">';
}
add_filter( 'generate_end_widget_title', 'tu_adjust_widget_title_end' );
function tu_adjust_widget_title_end() {
return '</h4>';
}
hi!
Where am I suposed to put this filter??? I tried in the custom CSS but it doesn't work there (sorry i'm not a programmer). Should I put that in the sidebar.php file in my child theme??? If this is it... Where at?
Thanks
mmm, so I add it in the functions.php or can I put it in "Elements" as a hook?
danke
I pasted the code in the funtions.php on my child theme and it crashed the site. Also not working in "Elements". Can you be more precise, please?
sorry to bother, thanks
thats odd, can you try the Code Snippets plugin mentioned in the document link?
I can't see an issue with the code (it Tom's so that would be rare :) )
thanks, it is working with code snippets but i'd rather not to use another pluggin (i have tons). Maybe I'm pasting the code in the wrong area of the functions.php file?
Where should it go??
<?php
/**
* GeneratePress.
*
* Please do not make any edits to this file. All edits should be done in a child theme.
*
* @package GeneratePress
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
// Set our theme version.
define( 'GENERATE_VERSION', '2.1.4' );
if ( ! function_exists( 'generate_setup' ) ) {
add_action( 'after_setup_theme', 'generate_setup' );
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* @since 0.1
*/
function generate_setup() {
// Make theme available for translation.
load_theme_textdomain( 'generatepress' );
// Add theme support for various features.
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link', 'status' ) );
add_theme_support( 'woocommerce' );
add_theme_support( 'title-tag' );
add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption' ) );
add_theme_support( 'customize-selective-refresh-widgets' );
add_theme_support( 'custom-logo', array(
'height' => 70,
'width' => 350,
'flex-height' => true,
'flex-width' => true,
) );
// Register primary menu.
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'generatepress' ),
) );
/**
* Set the content width to something large
* We set a more accurate width in generate_smart_content_width()
*/
global $content_width;
if ( ! isset( $content_width ) ) {
$content_width = 1200; /* pixels */
}
// This theme styles the visual editor to resemble the theme style.
add_editor_style( 'css/admin/editor-style.css' );
}
}
/**
* Get all necessary theme files
*/
require get_template_directory() . '/inc/theme-functions.php';
require get_template_directory() . '/inc/defaults.php';
require get_template_directory() . '/inc/class-css.php';
require get_template_directory() . '/inc/css-output.php';
require get_template_directory() . '/inc/general.php';
require get_template_directory() . '/inc/customizer.php';
require get_template_directory() . '/inc/markup.php';
require get_template_directory() . '/inc/element-classes.php';
require get_template_directory() . '/inc/typography.php';
require get_template_directory() . '/inc/plugin-compat.php';
require get_template_directory() . '/inc/migrate.php';
require get_template_directory() . '/inc/deprecated.php';
if ( is_admin() ) {
require get_template_directory() . '/inc/meta-box.php';
require get_template_directory() . '/inc/dashboard.php';
}
/**
* Load our theme structure
*/
require get_template_directory() . '/inc/structure/archives.php';
require get_template_directory() . '/inc/structure/comments.php';
require get_template_directory() . '/inc/structure/featured-images.php';
require get_template_directory() . '/inc/structure/footer.php';
require get_template_directory() . '/inc/structure/header.php';
require get_template_directory() . '/inc/structure/navigation.php';
require get_template_directory() . '/inc/structure/post-meta.php';
require get_template_directory() . '/inc/structure/sidebars.php';
So is that you're child Theme function file? As it looks like a copy of the parent Theme function?
Yes, i duplicated the parent and pasted the code at the end.
In other php files such as "comments.php" i also clonated the file to the child theme and made the changes and additions on the child comments.php clone
Am I doing it wrong? How is this supposed to work?
thanks (and sorry, lol)
haha - so the template files such as comments.php are ok to copy. The child theme function should be blank to start with, you can get a starter one from the links provided here, and should only contain your custom functions, not duplicates of any parent function.