Archived topic
Change Footer Widget Titles from H2 to Paragraph
7 replies · Started by Belinda on February 28, 2021
Hello,
I see that Davind recommends on this page to add the following code in order to accomplish this.
I'm new to this kind of work and can you please confirm if this code needs to be added to footer.php or functions.php? I basically need to change titles of footer widgets (like recent comments, copyright statement etc) to <p> from the default <h2>.
Thanks in advance!
add_filter( 'generate_start_widget_title', 'db_start_widget_title' );
function db_start_widget_title()
{
return '<p class="widget-title">';
}
add_filter( 'generate_end_widget_title', 'db_end_widget_title' );
function db_end_widget_title()
{
return '</p>';
}
Hi there,
We can't be if that would work unless we check your site. This is due to some site templates from the Site Libraries hooking a custom footer.
If you're using the default footer then that could work. :)
Here's how to add PHP - https://docs.generatepress.com/article/adding-php/
Thank you Elvin for the prompt response. Because my site has been speed optimized etc., I want to avoid adding new plugins if possible. I would really appreciate if you could kindly take a look inside the hood and advice. I will include the login info below.
That way, I can add the code directly to the footer.php and avoid adding new plugins.
Thank you so much!
Belinda
I've checked the site and David's code should work. :)
Thank you Elvin for your help and advice. Unfortunately, none of that worked. I tried the following variations. But none of them worked!
I added the following different codes to GeneratePress: footer.php right below the <?php so it looked like this.
<?php
add_filter( 'generate_start_widget_title','generate_remove_widget_title_h2' );
function generate_remove_widget_title_h2()
{
return '<p class="widget-title">';
}
add_filter( 'generate_end_widget_title','generate_remove_widget_title_end_h2' );
function generate_remove_widget_title_end_h2()
{
return '</p>';
}
/**
* The template for displaying the footer.
*
* @package GeneratePress
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
?>
</div>
</div>
<?php
/**
* generate_before_footer hook.
*
* @since 0.1
*/
do_action( 'generate_before_footer' );
?>
<div <?php generate_do_element_classes( 'footer' ); ?>>
<?php
/**
* generate_before_footer_content hook.
*
* @since 0.1
*/
do_action( 'generate_before_footer_content' );
/**
* generate_footer hook.
*
* @since 1.3.42
*
* @hooked generate_construct_footer_widgets - 5
* @hooked generate_construct_footer - 10
*/
do_action( 'generate_footer' );
/**
* generate_after_footer_content hook.
*
* @since 0.1
*/
do_action( 'generate_after_footer_content' );
?>
</div>
<?php
/**
* generate_after_footer hook.
*
* @since 2.1
*/
do_action( 'generate_after_footer' );
wp_footer();
?>
</body>
</html>
I tried adding the following variations on the above location. None of them worked.
add_filter( 'generate_start_widget_title','generate_remove_widget_title_h2' );
function generate_remove_widget_title_h2()
{
return '<p class="widget-title">';
}
add_filter( 'generate_end_widget_title','generate_remove_widget_title_end_h2' );
function generate_remove_widget_title_end_h2()
{
return '</p>';
}
add_filter( 'generate_start_widget_title','generate_remove_widget_title_h2' );
function generate_remove_widget_title_h2()
{
return '<div class="widget-title">';
}
add_filter( 'generate_end_widget_title','generate_remove_widget_title_end_h2' );
function generate_remove_widget_title_end_h2()
{
return '</div>';
}
add_filter( 'generate_start_widget_title', 'db_start_widget_title' );
function db_start_widget_title()
{
return '<p class="widget-title">';
}
add_filter( 'generate_end_widget_title', 'db_end_widget_title' );
function db_end_widget_title()
{
return '</p>';
}
Unfortunately, none of them worked.
Yes, of course, I cleared the cache using the WP Rocket plugin.
I would highly appreciate if you could help me solve this matter.
Belinda
Hi there,
you should never edit the theme function files unless they are a child theme ... and in this case those codes would not work there anyway :)
The document Elvin provided explains the methods that need to be applied.
If you're not using a Child Theme then the Code Snippets plugin is required - there will be no noticeable impact on site performance by using that plugin.
Hi David,
Thank you that worked. So no workarounds... no shortcuts :)
Many thanks Elvin and David.
Have a great day!
Belinda
Glad we could be of help!