Aleš Sýkora wrote

Get WordPress title for page, post, category, archive in Oxygen

26. 1. 2021 in ,

Want to create only one template for Header and Footer – the main template – in Oxygen sometimes? So You need to display the title of current page, post, archive, category in one place. It cannot be done with Oxygen conditionals :(. So you have to make it done with code block and custom PHP.

We will use this functions:


Use this code in Code Block

if ( is_category() ) {
		$title = single_cat_title( '', false );
	} elseif ( is_tag() ) {
		$title = single_tag_title( '', false );
	} elseif ( is_author() ) {
		$title = '<span class="vcard">' . get_the_author() . '</span>';
	} elseif ( is_post_type_archive() ) {
		$title = post_type_archive_title( '', false );
	} elseif ( is_tax() ) {
		$title = single_term_title( '', false );
	} elseif ( is_home() ) {
		$title = single_post_title( '', false );
	}  elseif ( is_page() ) {
		$title = single_post_title( '', false );
	} elseif ( is_single() ) {
		$title = single_post_title( '', false );
	} elseif ( is_search() ) {
		$title = "Search";
	} elseif ( is_404() ) {
		$title = "404 not found";
<h1 class="responsive-h1"><?php echo $title; ?></h1>

Put it in the code block and style with your custom classes.. I am using hte .responsive-h1 class.

Code block with dynamic Title

5 comments on “Get WordPress title for page, post, category, archive in Oxygen”

  1. Can you please also add the php code for the title for:
    – Search results page, and
    – 404 Error page


    1. Hello Mike! I have Updated the code with this:

      elseif ( is_search() ) {
      $title = "Search";
      } elseif ( is_404() ) {
      $title = "404 not found";

      Hopefully it help you.

Leave a Reply to Aleš Sýkora Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

More from category
Aleš Sýkora wrote
Fluent Forms activation – You do not have sufficient permissions to access this page.
25. 3. 2021 in
If you got “You do not have sufficient permissions to access this page.” error when you click on activation of Fluent Forms Pro licence, you need to go to the integration modules settings of Fluent Forms plugin and activate the plugin from there.
Read More
Aleš Sýkora wrote
Child posts menu for custom post type parent item
1. 2. 2021 in
This code will help you display menu of childs on current post. For example: Product 1 = parent has those child pages: – Product usage– How to– Disclaimer– Calculator When you put this child items menu in your template, it will show all childs of product 1 on all child pages and also on product […]
Read More
Aleš Sýkora wrote
Change WP Rocket lazyload treshold
21. 1. 2021 in
Default treshold for lazyload is 300px in WP-Rocket. That means that images that are within 300px of the viewport (browser window) are loaded for smooth user experience. If you like to load less images – for example 100px after viewport only – you can not set it up directly in WP Rocket’s settings page. To […]
Read More
magnifiercross linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram