Add content to a Tag Page

Hi,

how can I add some content in my Child Theme to a Tag Page? For example here:

Is there a special template for the Tag Pages?

Michael

1 Like

Hello Michael,

Thanks for asking. :slight_smile:

  1. If you would like to display custom title, then that can be changed from Posts > Tags > Archive Title.
  2. If you would like to display description or additional content, then please add following code in child theme function.php file.
add_action( 'x_before_view_global__index', 'print_custom_header' );
function print_custom_header(){ ?>
	<?php if(is_tag() ) : ?>
		<div id="blog_section" class="x-section" style="margin: 0px;padding: 45px 0px; background-color: transparent;">
			<div class="x-container max width" style="margin: 0px auto;padding: 0px;">
				<div class="x-column x-sm x-1-1" style="padding: 0px;">
				
					<?php if( is_tag() ) : ?>
						<p><?php echo tag_description(); ?></p>
					<?php endif; ?>
				</div>
			</div>
		</div>
	<?php endif; ?>
<?php }

Upon adding the the code you need to add the description in Posts > Tags > Description

Please note that above changes will require modification in theme files. I suggest you to please setup child theme before making any theme file changes. I am sharing few resources, please use them to download and setup child theme.

Additionally, if you would like to learn HTML, CSS and PHP I am sharing few resources that you take a look to get started and an interesting tool that you can use to speed up the development process.

HTML: https://www.w3schools.com/html/
PHP: http://php.net/manual/en/tutorial.php, https://www.w3schools.com/pHP/default.asp

I recommend you to watch following video that will help you to get started with CSS.

https://www.youtube.com/watch?v=MFR4WXiLzpc

Sometimes it can get a bit difficult to find out the right selector to be able to write the required CSS codes. A handy tool that can help you in this is Google Chrome dev tools. I am sharing the resource that you can refer to get started with dev tools.

https://developers.google.com/web/tools/chrome-devtools/css/

https://developers.google.com/web/tools/chrome-devtools/

https://www.youtube.com/watch?v=tP_kXBJWPhQ&t=200s

Thanks.

1 Like

Thank you for your answer.

With your code I can add content (like custom titel, description…) before the main archive.
But I like to add after the archive content.

How can I do that?

Michael

Hello Michael,

If you want to add add a custom content after the tag archive contents, please add the following code in your child theme’s functions.php file

// Displaying custom Content on Tag Page
// =============================================================================
function add_custom_content () {

  if( is_tag() ) { ?>
    
    <div class="custom-content">
    	<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer scelerisque eros eu pulvinar dictum. Nunc egestas massa at elit bibendum, cursus fringilla nunc faucibus. Proin dignissim efficitur nunc a cursus. In luctus mi in nisi condimentum, sed ornare enim tempor. Praesent semper ultricies tellus, rutrum fermentum leo viverra at. Sed a venenatis ante, non aliquam tortor. Aliquam erat volutpat. Curabitur felis elit, rhoncus et molestie in, auctor euismod lorem. Etiam viverra hendrerit metus, vitae ullamcorper metus ultricies ut. Ut eu ex id ligula viverra auctor at quis urna.</p>
    </div>
  
  <?php }

}
add_action('x_after_view_global__index', 'add_custom_content');

// =============================================================================

Hope this helps.

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