Skip to content

Snippet: Back To Projects Portfolio Header Button

This example snippet shows you how you can add a button to the page header on your portfolio posts that links back to the main portfolio page. You can of course do the same for any post type and after adding the snippet make sure to add your custom CSS to style the button exactly how you want.

// Add a back to projects button on single portfolio posts in the page header
function myprefix_portfolio_back_to_projects_button() {
	if ( is_singular( 'portfolio' ) ) {
		$portfolio_page = wpex_get_mod( 'portfolio_page' ); // Go to Portfolio > Post Type Editor to select your page
		$portfolio_page = $portfolio_page ? get_permalink( $portfolio_page ) : '';
		if ( $portfolio_page ) {
			$title = esc_attr( __( 'Back to projects', 'total' ) );
			echo '<a href="'. esc_url( $portfolio_page ) .'" title="'. $title .'" class="theme-button myprefix-back-to-projects">'. $title .'</a>';
add_action( 'wpex_hook_page_header_inner', 'myprefix_portfolio_back_to_projects_button', 99 );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top