This module allows users to smoothly scroll back to the top of the page.
The link fades in on the bottom right-hand side of the content area, after the browser window has been scrolled beyond a certain point, and remains fixed during scrolling.
If users continues scrolling, the button nicely reduces its opacity to be less distracting during navigation.
Note: The ideal place to add custom CSS in Oxygen is at Manage > Stylesheets in a new/existing Stylesheet.
Here is an example of customizing the color of the back to top button in regular and hover states:
/* change the background color of the icon - regular state */
.cd-top {
background-color: #333;
}
/* change the background color of the icon - hover state */
.js .cd-top:hover {
background-color: #000;
}
To change the back to top button shape from circular to a square, add this CSS:
.cd-top {
border-radius: 0;
}
The background image comes from the following line of the plugin for .cd-top
:
background: url(../img/cd-top-arrow.svg) no-repeat center 50%;
Here is sample CSS code to replace the image:
.cd-top {
background-image: url(/wp-content/uploads/2020/05/up-arrow.png);
}
Replace /wp-content/uploads/2020/05/up-arrow.png
in the above with the URL of your up icon image uploaded to your site’s media library.
By default the back to top button will be positioned 20px from the bottom. If you would to push it further up at smaller viewports add this sample CSS and modify as needed:
@media only screen and (max-width: 1023px) {
.cd-top {
bottom: 40px;
}
}
Here is an example of loading it only on all single posts.
Add this in a Code Snippet:
add_action( 'wp_enqueue_scripts', 'ot_load_back_to_top_conditionally', 100 );
/**
* Remove Back to Top button from loading everywhere except on single posts.
*/
function ot_load_back_to_top_conditionally() {
// if we are on a single post, abort.
if ( is_singular( 'post' ) ) {
return;
}
// remove Back to Top button.
remove_action( 'wp_head', 'Oxy_Toolbox_BackToTop::add_js_to_html' );
remove_action( 'wp_footer', 'Oxy_Toolbox_BackToTop::back_to_top_html' );
wp_dequeue_style( 'oxy_toolbox_back_to_top_style' );
wp_dequeue_script( 'oxy_toolbox_back_to_top_script' );
}
Add the following sample CSS:
@media only screen and (max-width: 479px) {
.cd-top {
display: none;
}
}
Add the following sample CSS to make the button smaller in size:
body .cd-top {
width: 30px;
height: 30px;
background-size: 35%;
}