Wordpress and tag pages title - wordpress

I would like to know how to remove the word "archives" from a category or tag page title of a WordPress theme? Thank you!

Look at the official docs of get_the_archive_title(). You can modify the content through filter like below.
add_filter( 'get_the_archive_title', function ( $title ) {
if( is_category() ) {
$title = single_cat_title( '', false );
}
return $title;
});

Related

Remove "Category:" word from Woocommerce Archive Pages

I want to remove just word Category: from the header on every product category page, like is shown on image below:
So that it will only show the category name, and nothing more. I know how to remove entire block, but haven't found out how to remove just that word. I found the solution below, but it doesn't do anything:
add_filter('woocommerce_show_page_title', function() {
return false;
});
You can filter out the "Category:" prefix by using the get_the_archive_title hook like this:
add_filter( 'get_the_archive_title', 'so_remove_category_prefix' );
function so_remove_category_prefix( $title ) {
$title = single_term_title( '', false );
return $title;
}
However, that will remove it for all terms (not just product categories, but blog categories, tags etc).
To specifically target product categories, you can use the is_product_category() function that is provided by WooCommerce:
add_filter( 'get_the_archive_title', 'so_remove_category_prefix' );
function so_remove_category_prefix( $title ) {
if ( is_product_category() ) {
$title = single_term_title( '', false );
}
return $title;
}

Custom Page Title Shortcode within another Shortcode

I use this function to obtain the title of post page in the content area:
function myshortcode_title( ){
return get_the_title();
}
add_shortcode( 'page_title', 'myshortcode_title' );
So, I have a plugin that when I use this shortcode below it read the text beetween the shortcode:
[responsivevoice voice="UK English Male"] Wonderful World [/responsivevoice]
So, what I'm doing and it's my question also is how can I put the "page title shortcode" within responsivevoice shortcode like this?
[responsivevoice voice="UK English Male"] [page_title] [/responsivevoice]
(It should get the title of the post page, but it doesn't work).
Choose one of the following options, and add the code snippet after:
add_shortcode( 'page_title', 'myshortcode_title' );
Option #1: [responsivevoice2]
add_shortcode( 'responsivevoice2', 'responsivevoice2' );
function responsivevoice2( $atts = array(), $content = '' ) {
if ( $content = do_shortcode( $content ) ) {
return RV_add_bblisten( $atts, $content );
}
return '';
}
Sample usage:
[responsivevoice2 voice="UK English Male"] [page_title] [/responsivevoice2]
This Shortcode allows you to use the [page_title] or any other Shortcodes in the
text to be spoken.
Option #2: [responsivevoice_page_title]
This Shortcode will always use the page title (or the title of the current post)
as the text to be spoken. With this Shortcode, you don't need the [page_title]
Shortcode anymore.
add_shortcode( 'responsivevoice_page_title', 'responsivevoice_page_title' );
function responsivevoice_page_title( $atts = array() ) {
if ( $page_title = get_the_title() ) {
return RV_add_bblisten( $atts, $page_title );
}
return '';
}
Sample usage:
[responsivevoice_page_title voice="UK English Male" /]

Rename the post title with media name - Wordpress

I have a wordpress website with customs posts and metas boxes.
One of these manage some pictures and I want to force the title of the post.
It should be the same as the name of the media uploaded.
Is it possible ? And how ?
Thank's
Manipulate the post title with a filter.
function change_post_title( $title, $id = null ) {
if ( is_single() ) {
$title = 'new title';
}
return $title;
}
add_filter( 'the_title', 'change_post_title', 10, 2 );
Thanks all for your help.
I have used a filter but this one :
function modify_post_title($data){
if($data['post_type'] == 'fcfm_photos' && isset($_POST['image'])) {
$data['post_title'] = substr($_POST['image'], -(strpos(strrev($_POST['image']),'/')));
}
return $data;
}
add_filter( 'wp_insert_post_data' , 'modify_post_title' , '99', 1 );
And when I save the post, the post title change automatically. This is what i want.

I want to change the 404 page title of a wordpress theme

I have a website that uses worpdress with catch box theme, and I want to change the 404 page title.
I looked for the "Nothing found for" sentence on the PHP files on the Editor but I did not find nothing.
I searched for the get_header(); method in editor to change the title but I did not find it.
see the title that I want to change
Have been already answered here: https://wordpress.stackexchange.com/questions/30873/how-to-change-404-page-title
Add the following to theme functions.php file
function theme_slug_filter_wp_title( $title ) {
if ( is_404() ) {
$title = 'ADD 404 TITLE TEXT HERE';
}
// You can do other filtering here, or
// just return $title
return $title;
}
// Hook into wp_title filter hook
add_filter( 'wp_title', 'theme_slug_filter_wp_title' );
You can use filter hook
function theme_slug_filter_wp_title( $title ) {
if ( is_404() ) {
$title = 'ADD 404 TEXT HERE';
}
return $title;
}
add_filter( 'wp_title', 'theme_slug_filter_wp_title' );
try this one for wordpress version 4.4+
file : function.php
function theme_slug_filter_wp_title($title_parts)
{
if (is_404()) {
$title_parts['title'] = 'My Custom Title Text';
}
return $title_parts;
}
add_filter('document_title_parts', 'theme_slug_filter_wp_title');

How to sort Wordpress title-tag parts?

I need to change the position of my title parts. Now my homepage renders:
"blogname separator description"
And I would like to place the blogname at the end:
"description separator blogname"
My theme supports title-tag and I read that it has 3 filters, which are:
add_theme_support( 'title-tag' );
pre_get_document_title short-circuits wp_get_document_title() if it returns anything other than an empty value.
document_title_separator filters the separator between title parts.
document_title_parts filters the parts that make up the document title, passed in an associative array.
How to use them in order to change the position of the title parts?
Change title part on homepage or front-page WordPress
#retroriff, if you need re-order of title and tagline as part of wp title on homepage, you can use filter document_title_parts, and fire with a function. First, we need to unset them, then re-build as order. Here my sample approach:
add_filter( 'document_title_parts', 'wp36469459_document_title_parts', 1, 1 );
function wp36469459_document_title_parts( $title )
{
if ( is_home() || is_front_page() ) {
//we unset title and tagline
unset( $title['title'], $title['tagline'] );
//re-build and order
$title['tagline'] = get_bloginfo( 'description', 'display' );
$title['title'] = get_bloginfo( 'name', 'display' );
}
return $title;
}
OR
add_filter( 'document_title_parts', 'wp36469459_document_title_parts', 1, 1 );
function wp36469459_document_title_parts( $title )
{
if ( is_home() || is_front_page() ) {
$_title = $title['title'];
$_tagline = $title['tagline'];
unset( $title['title'], $title['tagline'] );
$title['tagline'] = $_tagline;
$title['title'] = $_title;
}
return $title;
}
You can tweak the code as suit your need.
If you need only to reverse the title parts (for the home page), then this works:
function theme_document_title_parts($title) {
return (is_home() || is_front_page()) ? array_reverse($title) : $title;
}
add_filter('document_title_parts', 'theme_document_title_parts');

Resources