Change Copyright Text in Free GeneratePress Theme using Theme Customizer

In today’s tutorial, we will see how to change the copyright text from the footer of the Free GeneratePress theme using a theme customizer.

In my previous tutorial, I have shown that how to add a customizer option in the free GeneratePress theme. Today’s tutorial is based on that code. This code will not work without that code. So look at that code first, then follow this tutorial.

Remove Copyright Text in GeneratePress Free Version

We can easily change the code from theme functions.php. But the problem is, if the theme is updated then those codes will be deleted. To get rid of that, we can use the Code Snippets plugin to add our code.

The best way is to use the code in the child theme’s functions.php. If you don’t know how to create a child theme, you can follow my GeneratePress Child theme tutorial.

In our tutorial, we are going to make it dynamic. For example, the text that we want as copyright in the footer, if we write the code directly in functions.php then it will be very tough to alter the code again when we want to show another text.

That’s why the theme customizer is the best option to change the footer credit text. This is because we can easily change the text anytime without altering the code in functions.php. So, let’s check the code first.

function gpchild_copyright_text () {
	
	$search = array(
		'%copy%',
		'%current_year%',
		'%blog_name%',
		'%blog_url%'
	);

	$replace= array(
		'&copy',
		date( 'Y' ),
		get_bloginfo('name'),
		'<a href="'.get_site_url().'">'.get_bloginfo('name').'</a>'
	);
	$copyright_text = get_theme_mod('footer_credit_text');

	if( $copyright_text ){
		$copyright_text = str_replace( $search, $replace, $copyright_text);
	}
	
	return $copyright_text;
 }
add_filter( 'generate_copyright', 'gpchild_copyright_text' );

GeneratePress has a filter i.e. ‘generate_copyright’. By this filter, we can change our footer credit text or copyright text. In GeneratePress Premium has some options like %current_year%, %copy% etc. By using our code we can also use these features in GeneratePress Free theme.

Here get_theme_mod(‘footer_credit_text’) is the value of theme customizer footer textarea. Check the below image to understand it properly.

generatepress free footer copyright text

You can see the copyright text format. The %blog_url% will generate blog name in anchor text. So no need to write the blog name inside the anchor.

%copy%It will show the copyright symbol © 
%current_year% It will display the current year i.e. 2021
%blog_name%Show the blog name only i.e. CodeHasBugTutorial
%blog_url%Make blog anchor link like
<a href="https://codehasbug.com">CodeHasBug Tutorial</a>
About Ashis Biswas

A web developer who has a love for creativity and enjoys experimenting with the various techniques in both web designing and web development. If you would like to be kept up to date with his post, you can follow him.

Leave a Comment