Activate Back to top button for selected pages
There might be cases where you want the Back to top button to appear only on selected pages. As all of the Customizer options in GeneratePress are filterable, it’s very easy to do!
First you need to deactivate the Back to top button from the Customizer. Then, enter the following PHP code in your functions.php of a functionality plugin.
add_filter( 'option_generate_settings','gm_remove_back_to_top' ); function gm_remove_back_to_top ( $options ) { if ( is_page( 1259 ) ) { $options['back_to_top'] = 'enable'; } return $options; }
The above code enables the Back to top button for a page with ID 1259
. You can take it from there!
If I want this just for posts and not pages how would I best modify. I have tried using ‘is_single()’ but that doesn’t seem to work.
is_single()
is the correct conditional, Jason. Maybe check your code syntax. It works for me:Got it working, thanks! (not sure why it didn’t before)
Great!