Skip Navigation

[Resolved] Add dynamic heading from Archive Title (Where archive title is WPML compatible)

This support ticket is created 3 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 3.72 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by Waqar 3 years, 7 months ago.

Assisted by: Waqar.

Author
Posts
#2015051

We are adding a section that loads content from a custom type (created using toolset).

It should display the custom type's archive title and a slider with the items for that custom type.

The slider works great and was easy to implement.

What is the best way to dynamically load the archive title for the custom type?

Note: we are using WPML and ideally the loaded title should change when the selected language changes.

#2015575

Hi,

Thank you for contacting us and I'd be happy to assist.

To suggest the best way to achieve this, I'll need to understand exactly where this section with the archive title needs to be displayed.

Can you please share temporary admin login details, along with the link to the page where you'd like this title to be?

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

regards,
Waqar

#2016799

Thank you for assisting. The section is in an Astra custom layout but I am not asking for this specific scenario only - I would like a general use solution, as this is a common pattern. Please let me know what the options are and I will then be able to select the one best suited to my particular use case.

#2016801

Thank you for assisting. I am looking for a best practice general use solution, not one specific to a unique use case. Please let me know the options so I can choose the appropriate one.

#2018073

Thanks for writing back.

As a general requirement, you can register a custom shortcode, which uses the "the_archive_title" function to return the current archive page's title:
https://developer.wordpress.org/reference/functions/the_archive_title/

Example:


function custom_get_archive_title_func( $atts )
{
	$a = shortcode_atts( array(
		'before' => '',
		'after' => ''
	), $atts );
	return the_archive_title( $a['before'], $a['after'] );
}
add_shortcode( 'custom_get_archive_title', 'custom_get_archive_title_func' );

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

After that, you'll be able to use this shortcode in your archives, like this:


[custom_get_archive_title before='<h1>' before='</h1>']

Note: Feel free to adjust the before and after attribute values as needed, based on the HTML you'd like this title to wrap in.

And this title will be translate friendly too. All you'll need to do is go to WP Admin -> WPML -> String Translation and translate strings for your post type's singular and plural names and the default WordPress string like "Archive".