rtCamp notes, day 31 of undefined

Adding features to your theme,

WordPress allows us to add some predefined features ( activate some pre defined features on our theme ),

We can add the code add_theme_support( $support_name, $arguments ) to our themes functions.php to activate them,

Some of those are listed below

  • post-formats -> used to enable the support of post-formats throughout your theme.
  • post-thumbnails -> we can enable post-thumbnails for specific post types through this, passing the array of post-type as second argument.
    and then use this -> the_post_thumbnail(); to display
  • custom-background -> allows us to change the background of the site, we can also send default colour and image an array.
  • custom-header -> used to modify the header wordpress displays.
  • custom-logo -> used to add a custom site logo to wordpress.


For e.g. adding custom logo

add_action( 'after_setup_theme', function() {
	add_theme_support( 'custom-logo' );
} );

It will now give us the option in the Customizer to edit the site logo.

Conditional Tags

Conditional tags are used by wordpress to check several conditions throughout a theme to create more functional theme, they return boolean values and are usually about the current state of a page.

They only work when the main query has been executed as inside they are just relying on the data from the main WP_Query

Some commonly used tags:

is_admin() : -> if the admin dashboard or admin pages are being displayed

is_home() -> if the current page is the main page for the wordpress site

is_front_page() -> the main page of the blog is displayed, even if it is a static page

is_single() -> returns true for single posts.

is_singular() -> returns true if single post/page/attachment is being displayed

is_sticky() -> returns true if the current post is a sticky post.

is_date() -> is it the date archive?

is_archive() -> is it any type of archive?

is_search() -> is the current result related to search?

is_404() -> is it the 404 error?

Getting theme headers

We can get our theme headers we defined in style.css directly into our functions or other file by calling the function

wp_get_theme() we can use the get function in it to get a specific variable from the header. For example if we want to get the version number we can do

wp_get_theme()->get(‘Version‘)

We can also get the parent theme details by loading the parent function from it and doing get action on it, for example if we want to get the version number of the parent theme, we can use it like

wp_get_theme()->parent()->get(‘Version‘)

Leave a Reply

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