Woocommerce Product Page Breadcrumb-title edit - wordpress

i want it to be
I want to replace the top Store page name on the wordpress product page with the product name, can anyone help?
example:
i want it to be
How can I do? There is no such setting in the properties of the theme?

Not knowing what theme you are using or how the Shop title is being generated, try adding this code to your functions.php file
add_filter( 'woocommerce_page_title', 'woo_shop_page_title');
function woo_shop_page_title( $page_title ) {
if( 'Shop' == $page_title) {
return the_title();
}
}
This code replaces the page title Shop with the title of the product (post).

Related

ACF field in function.php

Following the request of an SEO agency, I'm trying to recover the content of a field (that I created via ACF in the product categories of WooCommerce) in a function of the functions.php file. I've tried a few tricks found on the net, but nothing works, I can't recover the content.
It's to replace the product category title by another one (the one of the new ACF field) and that this title is only displayed on the category archives of the site (not in the menus and other widgets where the default title is displayed.
Here is the code I did. I get the ID back fine if I display it, I make progress but nothing for $value
<?php
$query_id = get_queried_object_id();
function titre_seo_cat_prod() {
// recupere la valuur d'un post specifique
$value = get_field( 'titre_seo_categorie_de_produit', $query_id );
return $value;
}
?>

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' );

Wordpress Shortcode for keywords?

So, I know you can put:
function page_title_sc( ){
return get_the_title();
}
add_shortcode( 'page_title', 'page_title_sc' );
Into function.php to fetch the page title and get a [page_title] shortcode within Wordpress, but is it possible to do exactly that for keywords?
I put a focus keyword down in Yoast SEO and I would like to have a shortcode for that.
Or another idea: is there a way to have a custom shortcode field in every page? So that I only have to put something into that once and can use it as a shortcode within the whole page?
If you want a shortcode for Yoast to output the keyphrase automatically:
function wpso_61018203_output_yoast_keyphrase() {
// Make sure Yoast is installed/active.
if ( class_exists( 'WPSEO_Meta' ) ) :
// Hold the global post object.
global $post;
return WPSEO_Meta::get_value( 'focuskw', $post->ID );
endif;
}
add_shortcode('yoast_kw', 'wpso_61018203_output_yoast_keyphrase' );
You can then do this ['yoast_kw'] in your content, or use echo do_shortcode('[yoast_kw]'); in your template.
Use get_post_meta and grab _yoast_wpseo_focuskw:
function page_focus_keyword( ){
return get_post_meta(get_the_ID(), '_yoast_wpseo_focuskw');
}
add_shortcode( 'focus_keyword', 'page_focus_keyword' );
WordPress filters all content to make sure that no one uses posts and page content to insert malicious code in the database. This means that you can write basic HTML in your posts, but you cannot write PHP code.
And you want to use Wordpress shortcode for focus keyword.
Possible solution given on Wordpress.org Yoast SEO plugin support query on similar query, and checkout the linked solution
insert the below php snippet in functions.php
if(!function_exists('wpseoFocusKW'))
{
function wpseoFocusKW()
{
$focuskw = wpseo_get_value('focuskw', $post->ID);
echo $focuskw;
}
}
And to use the shortcode in another page for focused keyword, insert the below shortcode in any pages with yoast-seo plugin :
Shortcode for focus keyword
[<?php wpseoFocusKW();?>]

Link Woocommerce custom placeholder image to product page

On my woocommerce e-commerce page https://www.vattenliv.se/produkt-kategori/filter/ozon-och-proteinskimmer/ there are some products that does not have any product image set. Instead the custom placeholder image shows. Is there a way to make these placeholder images link to each product page, just like the other products?
The site uses the theme OceanpWP and Elementor page builder.
Peter
I believe the best way to do this is by using a child theme, to ovewrite the woocommerce function. This code in your child theme functions.php file should work.
<?php
if (!function_exists('woocommerce_get_product_thumbnail')) {
function woocommerce_get_product_thumbnail($size = 'shop_catalog', $deprecated1 = 0, $deprecated2 = 0) {
global $post;
if (has_post_thumbnail()) {
return ''.get_the_post_thumbnail($post->ID, $size).'';
}
elseif(wc_placeholder_img_src()) {
return ''.wc_placeholder_img( $size ).'';
}
}
}
?>

How to disable a sidebar in wordpress

I am using a wordpress theme with two sidebars. I want to disable one for them for a specific page but the code I found regarding disabling sidebar by applying check on function:
<?php get_sidebar() ?>
It will disable both of them. How can I disable one of them only. with the other sidebar working.
Please help!!!!
You can simply for example
<?php if (!is_page('about-me')) get_sidebar(); ?>
This will disable sidebar on about me page. If you put this on page.php (if have any) otherwise put this on index.php. Here 'about-me' is page slug but you can also use page id like is_page(5) and as well as page title too. To check multiple page using slug, id and title you can use an array like
is_page(array(42,'about-me','Contact'));
For more about is_page() function see http://codex.wordpress.org/Function_Reference/is_page
Or using filter in functions.php, simply put this in functions.php
function disable_footer_widgets( $sidebars_widgets )
{
if (is_single())
{
$sidebars_widgets['footer'] = false;
}
return $sidebars_widgets;
}
add_filter( 'sidebars_widgets', 'disable_footer_widgets' );
This is just an example, you have to change widget name.

Resources