Woocommerce: How to remove "Archive" in title? - wordpress

I'm trying to remove the word "Archive" from the page title.
How to remove it? By adding a filter?
Example:
My collections Archive | My sitename

Best to use Wordpress SEO by Yoast.
Within Titles & Metas go to the Taxonomies tab and update the Title template for Product Categories to remove the word Archive. Mine ended up looking like this:
%%term_title%% %%page%% %%sep%% %%sitename%%

you can rewrite the filter in functions.php so it fails, causing WooCommerce not the render it.
function override_page_title() {
return false;
}
add_filter('woocommerce_show_page_title', 'override_page_title');

If you are using the Yoast SEO (Versión 8.1.2), the options were move to:
Yoast SEO -> Search Appearance -> Taxonomies.
In there look up by Product categories (product_cat) and open it.
Then remove the Archives string from the head.

I know this is an old post but I tried the answers here and it didn't work.
I found the solution basing it off renegadesk's answer, but in addition of going to the Taxonomies Tab I also had to change it in the Post Types tab. See below:
Get Wordpress SEO by Yoast if you don't already have it, then click SEO > Titles & Metas > Post Types. Scroll down and look for the heading "Custom Post Type Archives". On the "Products", you can edit the content of this title. Mine now looks like this:
%%pt_plural%% %%page%% %%sep%% %%sitename%%

In woocommerce there seem to be 3 instances of Archives (case sensitive) one in
\wp-content\plugins\woocommerce\woocommerce-hooks.php around line 50
and 2 in \wp-content\plugins\woocommerce\woocommerce-template.php
around lines 240 ish
Perhaps one of those is what you're looking for and you may be able to modify code.

in addition to Ted C:
For this purpose Wordpress has already predifined functions starting with __return_.
In this case the function you are looking for is __return_false.
add_filter('woocommerce_show_page_title', '__return_false',10,0); will also work.
The last two params are the order of the function and the number of params passed to it.
It is always a good pratice to set them up but this is only necessary if you want to modify the default order (10) and the number of params passed (1).

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' );
So finally you have many condition like :
is_category
is_archive
is_tag
is_author
is_year
is_tax
https://developer.wordpress.org/reference/functions/get_the_archive_title/
Vincent.

wp-content/plugins/woocommerce/templates/archive-product.php
Edit this file archive-product.php and remove the below 3 lines.
<h1 class="page-title"><?php woocommerce_page_title(); ?></h1>
<?php endif; ?>
This will remove page title on shop page and all other pages.

Related

Show content before main content based on color attribute

I found a code snippet to display the content before the main content and it worked.
Currently the content is displayed on all pages. (except shop page)
The code :
add_action( 'woocommerce_before_main_content', 'BannerShop', 35 );
function BannerShop(){
if(!is_shop()){
echo '<img src="https://localhost/demosite/wp-content/uploads/2015/06/512x356.png" >';
}
}
What I want to ask is, how to display content only for color attribute products in the form of links.
Example :
The display (content) will ONLY SHOW when the url is like this :
mysite.com/color/red/
Sorry if the explanation is not good because I don't really understand this.
Any help is greatly appreciated.
thank you
I understand your question is about displaying that extra content, if the current query is for a product archive page only showing products of a certain attribute 'color'.
Each WooCommerce attribute is an independent taxonomy.
WordPress's is_tax('parameter') function checks, if the query is for an existing custom taxonomy archive page (other than category & tag) & if the query is for that specific taxonomy 'parameter', in your case 'color'.
So, this code snippet in your functions.php or equivalent plugin should work:
add_action( 'woocommerce_before_main_content', 'BannerShop', 35 );
function BannerShop(){
(is_tax('color')) {
echo '<img src="https://localhost/demosite/wp-content/uploads/2015/06/512x356.png" >';
}
}
Though, to make the above template WooCommerce override work, declare WooCommerce support for your theme by adding the following lines to your functions.php or plugin equivalent:
function theme_add_woocommerce_support() {
add_theme_support( 'woocommerce' );
}
add_action( 'after_setup_theme', 'theme_add_woocommerce_support' );

Woocommerce Wordpress How do I get the Search term as a dynamic variable

I'm trying to get the search term within a woocommerce page to display it dynamically on the results page so the user knows what term they searched on.
ex. "Showing results for $searchTerm"
Is there a way to get the search term from the page that was used?
You can make use of the get_search_query() and is_search() functions like this:
add_action( 'woocommerce_before_main_content', 'show_search_query_on_page', 1 );
function show_search_query_on_page() {
if(is_search()) {
echo '<h2>Showing results for: '.get_search_query().'</h2>';
}
}
I got this working through shortcodes by editing the functions.php file to include:
add_shortcode('searchterm', 'get_searchterm');
function get_searchterm() {
return $_GET['ixwpss'];
}
Then I could use [searchterm] as a shortcode on the page. Unfortunately I had to "touch" the php file.

Is there plugin for WP to show latest news with specific word in title or somewhere?

I need help with WordPress. For example, I have 100 posts in my blog, and only one post has a word: "HOT". I'd like to show this post on the right side (like widget). Can you advise me something?
There are plugins like "Recent Posts Widget Extended" that can filtered by tag or filter the post query on functions.php like :
add_filter( 'rpwe_default_query_arguments', 'your_custom_function' );
function your_custom_function( $args ) {
$args['s'] = 'HOT';
return $args;
}

Add specific words to WordPress custom type slug

I have a WordPress installation with a custom type (places) wich produces this permalink structure:
http://example.com/places/the-first-site/
And I would like to show all my sites like this:
http://example.com/places/visit-the-first-site-and-enjoy/
where 'visit' and 'and-enjoy' would be always those specific words (constants).
Even better I would like to put a custom taxonomy I have (year) as a metadata
places/visit-the-first-site-and-enjoy-1985/
I can access the DB and modify the post name of all post, but I would have to do for the new post also, and I'm looking for some automated rule, but can't find how to do.
Maybe some rewrite rule, but I don't know how to do it.
Any ideas??
You do not have to edit anything in your database nor any codes in your WordPress installation; you can achieve that directly from your WordPress administration panel.
From your Dashboard, click on the Permalink sub-menu under Settings; there, you will have to select the Custom Structure option and set it as follow in order to achieve your desired effect:
/places/visit-%postname%-and-enjoy-%year%/
Please note: here, we made use of both %postname% and %year% Structure Tags so as to get names of posts with their corresponding year of publication respectively.
Don't forget to click on the Save Changes button on the page in order to effect your changes.
... Read more on Permaklinks (for general knowledge).
For a custom post type and taxonomies as expressed further in comments, you will need a custom solution which will require a little bit of coding and or tweaking, depending on your abilities; you may use this handy plugin (Custom Post Type Permalinks) from the WordPress.org Plugins repository.
This posts should equally be of great help to you, to getting started and understanding further, should you chose to code.
You have différent hook like save_post or pending_to_publish, where you can set or change the "post_name" (that's corresponds to the permalink slug).
To Add specific words to WordPress custom type slug You have to Register custom rewrite rules.
suppose this is Your URL http://example.com/places/the-first-site !
and you have a post type places.
function add_rewrite_rules()
{
$wp_rewrite->add_rewrite_tag('%places%', '([^/]+)', 'places=');
$wp_rewrite->add_rewrite_tag('%state%', '([^/]+)', 'state=');
$wp_rewrite->add_permastruct('places', 'places/visit-%state%-and-enjoy/', false);
}
function permalinks($permalink, $post, $leavename)
{
$no_data = 'no-data';
$post_id = $post->ID;
if($post->post_type != 'story' || empty($permalink) || in_array($post->post_status, array('draft', 'pending', 'auto-draft')))
return $permalink;
$state = get_post_meta($post_id, 'location', true);
if(!$state)
$state = $no_data;
$permalink = str_replace('%state%', $state, $permalink);
return $permalink;
}
add_action('init', 'add_rewrite_rules');
add_filter('post_type_link', 'permalinks', 10, 3);
put this code in your custom post type plugin. and if get page not found error please change your permalink setting. or make a custom template file to show this post.

How to create two different single.php for same post type?

I have a post type named 'Property'.
I want to show single post in two different way.
if anyone click on post then it will shows a simple layout with name of post and description.
Now i have also category for beds. now if anyone goes in category '2 Bed' then you can see all post with '2 Bed' categories('its done'). but now if anybody click on post then it have to show different single page.
my English is very bad so please excuse it.
You can set up individual templates for a single category by using the single_template hook.
Put this in your functions.php file:
function my_category_templates($single_template) {
global $post;
if ( in_category( 'property' )) {
$single_template = dirname( __FILE__ ) . '/single-property.php';
}
// Copy the above for your other categories
return $single_template;
}
add_filter( "single_template", "my_category_templates" );
You can then create individual single templates for each category, just add more conditions and point them to the template you create.
There is the concept of Category Templates as dictated by the
Template Hierarchy but because you are asking how to display a "single" post based on category, you will want to use the in_category() Conditional Tag in the Template file you use to display singe posts. The Loop article has an example of using in_category.
Or look at this concept:
http://www.nathanrice.net/blog/wordpress-single-post-templates/
Or this:
http://justintadlock.com/archives/2008/12/06/creating-single-post-templates-in-wordpress
Or this plugin:
http://wordpress.org/extend/plugins/custom-post-template/
Or this plugin:
http://guff.szub.net/2005/07/21/post-templates-by-category/
So according to the Wordpress template hierarchy there is only one single.php, that cannot be separated by category (like the archive page for example.)
https://developer.wordpress.org/themes/basics/template-hierarchy/
So in this case I suggest you read the current category id in your single.php file and then adjust the content to your needs. You can use get_the_category() do do this (reference: https://developer.wordpress.org/reference/functions/get_the_category/) which will return you an array with categories. In my simple example I just pick the first category to do something:
$categories = get_the_category();
$category_id = $categories[0]->cat_ID;
if($category_id == 1) echo 'do something here';
Thanks for you help. I am done with it myself.
I create single.php for simple format and and in category result i didn't use the_permalink and call id of post and made a url like http://localhost/demo/page?id=$id

Resources