So, I have in the menu a link to a taxonomy archive that shows every product associated with that taxonomy.
Wordpress shows the correct page-title in category/tag archive, instead it shows the latest product title in the taxonomy page, that is nonsense.
I know that there's something about archive.php
elseif ( is_category() )
$title = sprintf( __( 'Category Archives: %s', 'mirage' ), '<span>' . single_cat_title( '', false ) . '</span>' );
elseif ( is_tag() )
$title = sprintf( __( 'Tag Archives: %s', 'mirage' ), '<span>' . single_tag_title( '', false ) . '</span>' );
elseif ( is_day() )
$title = sprintf( __( 'Daily Archives: %s', 'mirage' ), '<span>' . get_the_date() . '</span>' );
I tried to add an is_tax() etc. but nothing seems to reflect on the frontend.
I need to get the current taxonomy name and put it in the same page title.
Hope I made it clear. Thanks.
You can use:
elseif ( is_product_taxonomy() )
single_term_title();
endif;
Related
I am trying to fix the linting issue here is code.
function get_the_breadcrumb() {
if ( ! is_front_page() ) {
// Start the breadcrumb with a link to your homepage.
echo '<div class="o__breadcrumb">';
echo '<a href="';
echo esc_html( get_option( 'home' ) );
echo '"> Home';
echo '</a> <span> ';
echo esc_html( Load::atom( 'icons/breadcrumb_arrow' ) );
echo '</span>';
// Check if the current page is a category, an archive or a single page. If so show the category or archive name.
if ( is_category() || is_single() ) {
the_category( 'title_li=' );
} elseif ( is_archive() || is_single() ) {
if ( is_day() ) {
/* translators: %s: text term */
printf( esc_html( __( '%s', 'text_domain' ) ), esc_html( get_the_date() ) );
} elseif ( is_month() ) {
/* translators: %s: text term */
printf( esc_html( __( '%s', 'text_domain' ) ), get_the_date( _x( 'F Y', 'monthly archives date format', 'text_domain' ) ) );
} elseif ( is_year() ) {
/* translators: %s: text term */
printf( esc_html( __( '%s', 'text_domain' ) ), get_the_date( _x( 'Y', 'yearly archives date format', 'text_domain' ) ) );
} else {
esc_attr_e( 'Blog Archives', 'text_domain' );
}
}
// If the current page is a single post, show its title with the separator.
if ( is_single() ) {
echo '<span>';
echo esc_html( Load::atom( 'icons/breadcrumb_arrow' ) );
echo '</span>';
the_title();
}
// If the current page is a static page, show its title.
if ( is_page() ) {
echo the_title();
}
// if you have a static page assigned to be you posts list page. It will find the title of the static page and display it. i.e Home >> Blog.
if ( is_home() ) {
global $post;
$page_for_posts_id = get_option( 'page_for_posts' );
if ( $page_for_posts_id ) {
$post = get_page( $page_for_posts_id );
setup_postdata( $post );
the_title();
rewind_posts();
}
}
echo '</div>';
}
}
Linting response
FOUND 3 ERRORS AFFECTING 3 LINES
----------------------------------------------------------------------
193 | ERROR | Strings should have translatable content
196 | ERROR | Strings should have translatable content
199 | ERROR | Strings should have translatable content
Line number 193
printf( esc_html( __( '%s', 'text_domain' ) ), esc_html( get_the_date() ) );
Line number 196
printf( esc_html( __( '%s', 'text_domain' ) ), get_the_date( _x( 'F Y', 'monthly archives date format', 'text_domain' ) ) );
Line number 199
printf( esc_html( __( '%s', 'text_domain' ) ), get_the_date( _x( 'Y', 'yearly archives date format', 'text_domain' ) ) );
It's because you have %s as the text inside the translation function call __(...), which is not translatable.
Instead you should have your printf() call inside the translation call, so the translator can actually see what the heck you're trying to translate.
But, you shouldn't be trying to translate the date this way. It won't work because the date is always changing and the way __() translation works is by matching the exact string passed in to a translation. According to this answer, you should use date_i18n
And why are you trying to translate the date formatting strings you are passing to get_the_date, those are code values used by php, they don't change based on where you are. Translating these can only cause you problems.
You also call esc_html twice on line 193.
So, instead you should write your lines of code like so:
Line number 193
esc_html( date_i18n( get_the_date() ) );
Line number 196
esc_html( date_i18n( get_the_date('F Y') ) );
Line number 199
esc_html( date_i18n( get_the_date( 'Y' ) ) );
Note, I don't think the esc_html calls are actually necessary here, since the internals is just WordPress functions that only return dates... no html should be in there
I am trying to remove the words "Category Archives:" on the posts category page or The7 Wordpress Theme.
This one really has me stumped. I have gone through every file in the theme that I can think of and even tried to change this via the SEO plugin but am having no luck.
I was wondering if anyone had any ideas?
Here is the development site address: http://bellparktest.com/category/research-center/
Thank you,
Derek
OK- First of all - You should use the theme's child theme to make this kind of modification because when you make an update in the future it will wipe out all your changes.
You should look for the function "function presscore_get_page_title()" inside > wp-content > themes > dt-the7 > inc > helpers> .
copy it from line 12: "if ( ! function_exists( 'presscore_get_page_title' ) ) :"
to line 97 "endif;"
paste it inside your child theme "function.php" > wp-content > themes > dt-the7-child .
then change 'category' => __( 'Category Archives: %s', 'the7mk2' ), to 'category' => __( ' %s', 'the7mk2' ),
You should get something like this:
// THIS FUNCTION REMOVES "Category Archives:" FROM BLOG POSTS
if ( ! function_exists( 'presscore_get_page_title' ) ) :
/**
* Function return current page title.
*
* #return string
*/
function presscore_get_page_title() {
$default_page_title_strings = array(
'search' => __( 'Search Results for: %s', 'the7mk2' ),
'category' => __( '%s', 'the7mk2' ),
'tag' => __( 'Tag Archives: %s', 'the7mk2' ),
'author' => __( 'Author Archives: %s', 'the7mk2' ),
'day' => __( 'Daily Archives: %s', 'the7mk2' ),
'month' => __( 'Monthly Archives: %s', 'the7mk2' ),
'year' => __( 'Yearly Archives: %s', 'the7mk2' ),
'archives' => __( 'Archives: ', 'the7mk2' ),
'page_404' => __( 'Page not found', 'the7mk2' ),
'blog' => __( 'Blog', 'the7mk2' ),
);
/**
* Filter all default titles at once.
*
* #since 4.2.1
*/
$page_title_strings = apply_filters( 'presscore_page_title_strings', $default_page_title_strings );
$page_title_strings = wp_parse_args( $page_title_strings, $default_page_title_strings );
$title = '';
if ( is_home() && ! is_front_page() ) {
$title = single_post_title( '', false );
} elseif ( is_page() || is_single() ) {
$title = get_the_title();
} elseif ( is_search() ) {
$title = sprintf( $page_title_strings['search'], '<span>' . get_search_query() . '</span>' );
} elseif ( is_archive() ) {
if ( is_category() ) {
$title = sprintf(
$page_title_strings['category'],
'<span>' . single_cat_title( '', false ) . '</span>'
);
} elseif ( is_tag() ) {
$title = sprintf( $page_title_strings['tag'], '<span>' . single_tag_title( '', false ) . '</span>' );
} elseif ( is_author() ) {
the_post();
$title = sprintf(
$page_title_strings['author'],
'<span class="vcard"><a class="url fn n" href="' . esc_url(
get_author_posts_url( get_the_author_meta( 'ID' ) )
) . '" title="' . esc_attr( get_the_author() ) . '" rel="me">' . get_the_author() . '</a></span>'
);
rewind_posts();
} elseif ( is_day() ) {
$title = sprintf( $page_title_strings['day'], '<span>' . get_the_date() . '</span>' );
} elseif ( is_month() ) {
$title = sprintf( $page_title_strings['month'], '<span>' . get_the_date( 'F Y' ) . '</span>' );
} elseif ( is_year() ) {
$title = sprintf( $page_title_strings['year'], '<span>' . get_the_date( 'Y' ) . '</span>' );
} else {
$title = $page_title_strings['archives'];
}
} elseif ( is_404() ) {
$title = $page_title_strings['page_404'];
} else {
$title = $page_title_strings['blog'];
}
return apply_filters( 'presscore_get_page_title', $title );
}
endif;
I'm not sure about 'Category Archives:', I only see 'Category:'—that can be removed e.g. with the plugin 'Slash Admin' ('Frontend > Miscellaneous > Remove "Category:" from archives'). That seems to accomplish the task as follows (remove the 'if' around the 'add_filter' if you implement this yourself):
/*
* Remove "Category:" from archives
*/
function slashadmin_remove_category( $title ) {
if ( is_category() ) {
$title = single_cat_title( '', false );
}
if ( is_post_type_archive() ) {
$title = post_type_archive_title( '', false );
}
if ( is_tax() ) {
$title = single_term_title( '', false );
}
return $title;
}
if ( slash_admin( 'remove_category' ) ) {
add_filter( 'get_the_archive_title', 'slashadmin_remove_category', 10, 2 );
}
Disable the page title via Custom CSS located in Advanced CSS in Theme Options.
.category-research-center .page-title {
display: none !important;
}
You have this filter for all cases: "get_the_archive_title". But then there are different cases.
For exemple for simple category you can do :
function prefix_category_title( $title ) {
if(is_category()){
$title = single_cat_title( '', false );
}
return $title;
}
add_filter( 'get_the_archive_title', 'prefix_category_title' );
For custom post type you should do :
function prefix_category_title( $title ) {
if(is_archive('slug-of-your-custom-post-type')){
$title = single_cat_title( '', false );
}
return $title;
}
add_filter( 'get_the_archive_title', 'prefix_category_title' );
I am trying to change some text on my WooCommerce-based WP Website.
Essentially, through a filter using the str_replace I'm trying to change the text '%s reviews for %s' to be something else.
This text is included in the single-product-reviews.php file.
See below:
<h2><?php
if ( get_option( 'woocommerce_enable_review_rating' ) === 'yes' && ($count = $product->get_review_count() ) )
printf( _n( '%s review for %s', '%s reviews for %s', $count, 'woocommerce' ), $count, get_the_title() );
else
_e( 'Reviews', 'woocommerce' );
?></h2>
In order to do this I'm trying to use the following, but it doesn't seem to work. I'm not sure what string I should be targetting.
function lnz_replace_content()
{
echo str_replace("%s reviews for %s","%s comments about %s", $product);
}
add_filter('init','lnz_replace_content');'
I've had a go with gettext too but that doesn't seem to work either in this case.
OP Update
I've had a go at using gettext, but it doesn't seem to work in this case.
As previously mentioned, I'm targeting the following code (in single-product-review.php)
<h2><?php
if ( get_option( 'woocommerce_enable_review_rating' ) === 'yes' && ( $count = $product->get_review_count() ) )
printf( _n( '%s review for %s', '%s reviews for %s', $count, 'woocommerce' ), $count, get_the_title() );
else
_e( 'Reviews', 'woocommerce' );
?></h2>
If I use 'gettext' to replace 'Reviews' it works fine. If I try and get it to replace '% review for %s' it doesn't work.
Any ideas why.
you can do this with 2 ways:
1) change in language file:
msgid "%s reviews for %s"
msgstr "%s comments about %s"
msgid "%s review for %s"
msgstr "%s comment about %s"
2) chang code:
<h2><?php
if ( get_option( 'woocommerce_enable_review_rating' ) === 'yes' && ($count = $product->get_review_count() ) )
printf( _n( '%s review for %s', '%s reviews for %s', $count, 'woocommerce' ), $count, get_the_title() );
else
_e( 'Reviews', 'woocommerce' );
?></h2>
to
<h2><?php
if ( get_option( 'woocommerce_enable_review_rating' ) === 'yes' && ($count = $product->get_review_count() ) )
printf( _n( '%s comment about %s', '%s comment about %s', $count, 'woocommerce' ), $count, get_the_title() );
else
_e( 'Reviews', 'woocommerce' );
?></h2>
You can use the template overrides to override single-product-reviews.php by copying it into your theme's woocommerce folder.
or you can filter gettext from your theme's functions.php
add_filter( 'gettext', 'theme_change_comment_field_names', 20, 3 );
/**
* Change comment form default field names.
*
* #link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
*/
function theme_change_comment_field_names( $translated_text, $text, $domain ) {
if ( is_singular() ) {
switch ( $translated_text ) {
case '%s reviews for %s' :
$translated_text = __( '%s comments for %s', 'theme_text_domain' );
break;
case 'Related Products' :
$translated_text = __( 'Related Opportunities', 'theme_text_domain' );
break;
}
}
return $translated_text;
}
I am currently developing a WordPress site and would like to know what to change in the template-tags.php file to remove the date, time and author name.
Here is the code which I believe I need to change although each time I do I am greeted with the dreaded screen of death.
if ( ! function_exists( 'makewp005_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
*/
function makewp005_posted_on() {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) )
$time_string .= '<time class="updated" datetime="%3$s">%4$s</time>';
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
printf( __( '<span class="posted-on">%1$s</span> <span class="byline"> %2$s</span>', 'makewp005' ),
sprintf( '%2$s',
esc_url( get_permalink() ),
$time_string
),
sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s">%2$s</a></span>',
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_html( get_the_author() )
)
);
}
endif;
Thanks!
Why don't you use the CMS / API to remove them?
I believe this is the option to remove post info;
Larger: http://puu.sh/8rzux.png
So basically you want remove everything this function does.
if ( ! function_exists( 'makewp005_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
*/
function makewp005_posted_on() {}
endif;
In my archives.php file in my custom WordPress theme, I have the following code:
<div class="page-title">
<?php
if ( is_day() ) :
printf( __( 'Daily Archives: %s', 'sturd' ), '<span>' . get_the_date() . '</span>' );
elseif ( is_month() ) :
printf( __( 'Monthly Archives: %s', 'sturd' ), '<span>' . get_the_date( _x( 'F Y', 'monthly archives date format', 'sturd' ) ) . '</span>' );
elseif ( is_year() ) :
printf( __( 'Yearly Archives: %s', 'sturd' ), '<span>' . get_the_date( _x( 'Y', 'yearly archives date format', 'sturd' ) ) . '</span>' );
else :
_e( 'Archives', 'sturd' );
endif;
?>
</div>
I want there to be another statement so that if this is a category page, it displays just the category title in the page title div, and not just the word Archives (as it does currently).
I hope this is posted in the correct section.
Thanks in advance.
Sam
First of all, I suggest you get aquainted with the WP template hierarchy. I would usually suggest using a separate category.php template file for displaying categories, and using single_cat_title() for displaying the category name.
If you want to use the main archive.php template, you can add an is_category() clause and then use single_cat_title() to get the name.