Hallo, I do some onpage optimasations and need to change tow things.
-
How to remove the meta title tag?
<title>%Pagetitle%</title>
- How to remove the word "Tag: " and "Category: " for them archives H1 titles?
thanks Jochen
Hey Jochen,
Both your questions are WP related π
- To remove the page title, you can do
remove_theme_support( 'title-tag' )
. - Beans use
get_the_archive_title()
for the archive title which unfortunately doesn't have any other way to modify the title other than using theget_the_archive_title
filter (you can also usebeans_archive_title_text_output
filter. The only way I can see is tostr_replace()
the words you want to remove or rebuild the output according to your needs.
Hope that helps,
PS: The WP dev world would be so much easier if WordPress core functions were using the Beans HTML API right lol π
nice, there is already an exmaple at https://developer.wordpress.org/reference/functions/get_the_archive_title/
function my_theme_archive_title( $title ) {
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 );
}
return $title;
}
add_filter( 'get_the_archive_title', 'my_theme_archive_title' );
thanks you
This is the code to remove post and page titles: // Remove the post title.
beans_remove_action( 'beans_post_title' );
How do I only remove the page titles and not the post titles?
I tried the above mentioned code
remove_theme_support( 'title-tag' )
and it did not work for me.
Hi Paarl,
You may wrap the remove title action in a conditional statement to make sure it doesn't apply to pages as follow:
add_action( 'wp', 'example_setup_document' );
function example_setup_document() {
if ( false === is_page() ) {
beans_remove_action( 'beans_post_title' );
}
}
Have fun,
Hei Thierry
I see you have been communicating with Chris...:) (As you have started to also call me Paarl..:)
I found a CSS option:
.page .uk-article-title { display: none; }
As it seems a bit simpler then having to create a function to remove the page titles. It would be great to have a simple beans_remove_action( 'beans_PAGE_title' );
As I would think it is pretty common to hide the page title.
Thanks Thierry!
Hi Paal,
Hiding elements on the page isn't good practice, especially titles (for SEO, accessibility, size etc.). Therefore it is much better to prevent the title from being output, which is a much more elegant way of doing things anywhay.
Regarding adding a beans_PAGE_title
hook, this isn't really possible in a sense that all actions are following the same pattern for the ids, it uses the callback function name as for the id.
Have fun,
I removed the page titles from the pages but wanted it to remain on the blog page. This is the code that I used.
// Remove the page title from all pages except the blog page.
add_action( 'wp', 'setup_document_remove_pagetitle' );
function setup_document_remove_pagetitle() {
if ( false === is_single() and !is_home() ) {
beans_remove_action( 'beans_post_title' );
}
}
This means that one will see the page title on posts and the blog page. Even though the home page on the site is not the blog page it worked.