How can I put a back to top button?

Hi, as my website has many published listings, and on mobile, after scrolling down the listings it is not easy to go back to the top of the page, I was wondering if it was possible to add a “back to top button”, such as a classic arrow button to go to the top of the page instead of scrolling up again.

Hi, this code snippet will take you to the previous page. But i think what you need is a button to scroll to the top. Maybe hivepress support team has a code snippet for that instead

add_filter(
	'hivepress/v1/templates/listing_view_page',
	function( $template ) {
		return hivepress()->helper->merge_trees(
			$template,
			[
				'blocks' => [
					'page_content' => [
						'blocks' => [
							'custom_back' => [
								'type'    => 'content',
								'content' => '<a style="float:right" href="javascript: history.go(-1)"><i class="hp-icon fas fa-angle-left"></i> Back</a>',
								'_order'  => 5,
							],
						],
					],
				],
			]
		);
	}
);
2 Likes

Thank you very much. I will try that snippet. For a “back to top” button I downloaded the “To Top” plugin which worked perfectly!

1 Like

I was just going to mention that one, I found it as well. Thanks!

1 Like

is it a PHP snippet? because it does not seem to work :frowning: I can’t see the button on my website

Yes it is a php snippet used with code snippet plugin. It works for me on listinghive, not sure with the other themes. You should see a back button on top, when the user is on the listing’s landing page.

1 Like

oh now it is working thank you very much!!!

do you know how to put a back button that works on every page of the listing hive website? I would like the back button to appear on every page not just on the listing’s landing page. do you know something that might work?

Sorry I’m not a developer, Im just an average Joe, who has collected a list of code snippets from others on this forum.

Maybe hivepress support team can help you with that?

1 Like

ahaha ok thank you very much!

1 Like

You can try using WordPress hooks instead, e.g. wp_footer to echo the button HTML in the website footer section, then it’ll be added to all pages.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.