I'm using the following function to remove the product title from the breadcrumbs displayed on the product page:
add_filter( 'woocommerce_get_breadcrumb', 'ed_change_breadcrumb' );
function ed_change_breadcrumb( $breadcrumb ) {
if(is_singular()){
array_pop($breadcrumb);
}
return $breadcrumb;
}
It works in that it does remove the title, but it also stops the last category/sub-category from being a hyperlink. How can I fix that?
For example:
Original breadcrumb
<a>Home</a> / <a>Category</a> / <a>Sub Category</a> / Product Title
Result of the above function
<a>Home</a> / <a>Category</a> / Sub Category
I need the Sub Category to still be clickable after removing the product title from the breadcrumbs.
Thanks
Your code works but the last element in the breadcrumbs never contains a link through the code used in global/breadcrumb.php template file on line 34
This template can be overridden by copying it to yourtheme/woocommerce/global/breadcrumb.php.
So you can remove your filter hook and apply the following code in the template file so that it provides a link to the last element when is_product() is true
Note: is_product() - Returns true on a single product page. Wrapper for is_singular()
Replace
if ( ! empty( $breadcrumb ) ) {
echo $wrap_before;
foreach ( $breadcrumb as $key => $crumb ) {
echo $before;
if ( ! empty( $crumb[1] ) && sizeof( $breadcrumb ) !== $key + 1 ) {
echo '' . esc_html( $crumb[0] ) . '';
} else {
echo esc_html( $crumb[0] );
}
echo $after;
if ( sizeof( $breadcrumb ) !== $key + 1 ) {
echo $delimiter;
}
}
echo $wrap_after;
}
With
if ( ! empty( $breadcrumb ) ) {
echo $wrap_before;
foreach ( $breadcrumb as $key => $crumb ) {
echo $before;
if ( ! empty( $crumb[1] ) && sizeof( $breadcrumb ) !== $key + 1 ) {
echo '' . esc_html( $crumb[0] ) . '';
} else {
if ( is_product() ) {
unset($crumb);
} else {
echo esc_html( $crumb[0] );
}
}
echo $after;
if ( sizeof( $breadcrumb ) !== $key + 1 ) {
if ( is_product() && sizeof( $breadcrumb ) == $key + 2 ) {
echo '';
} else {
echo $delimiter;
}
}
}
echo $wrap_after;
}
Related
This code works perfect to search products by title on woocommerce .. ( dashbord backend ). However, it's affecting the search on media library, When the code is active it messes up the search in Media library Wordpress.... Is it possible to change the code to target only products instead of images, etc - media library. ???? Thank you.
function __search_by_title_only( $where, &$wp_query )
{
global $wpdb,$typenow,$pagenow;
if ( 'product' === $typenow && isset( $_GET['s'] ) && 'edit.php' === $pagenow ) {
$search_ids = array();
$terms = explode( ' ', $_GET['s'] );
foreach ( $terms as $term ) {
if ( is_numeric( $term ) ) {
$search_ids[] = $term;
}
if ( $search_term = $_GET['s'] ) {
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'%' . esc_sql( like_escape( $term ) ) . '%\'';
}
}
return $where;
}
}
add_filter('posts_search', '__search_by_title_only', 500, 2);
I've got following php function:
if ( ! function_exists('meteorite_sitebranding') ):
function meteorite_sitebranding() {
$logo_light = get_theme_mod( 'logo_light', '' );
$has_custom_logo = has_custom_logo();
if ( $has_custom_logo || $logo_light) {
if ( function_exists( 'the_custom_logo' ) && has_custom_logo() && is_front_page() || is_home() ) {
the_custom_logo();
}
elseif ( function_exists( 'the_custom_logo' ) && has_custom_logo() ) {
echo '<img src="logo_color.png" class="custom-logo" alt="Auplo" itemprop="logo" />';
}
elseif ( $logo_light ) {
echo '<img class="site-logo light" src="' . esc_url($logo_light) . '" alt="' . esc_attr(get_bloginfo('name')) . '" />';
}
} else {
echo '<div class="site-brand">';
if ( is_front_page() && is_home() ) :
echo '<h1 class="site-title">' . get_bloginfo('name', 'display') . '</h1>';
else :
echo '<p class="site-title">' . get_bloginfo('name', 'display') . '</p>';
endif;
echo '<p class="site-description">' . get_bloginfo('description', 'display') . '</p>';
echo '</div>'; // /.site-brand
}
}
endif;
the function works well. But i would like to finetune it a bit. My question is related to part:
if ( function_exists( 'the_custom_logo' ) && has_custom_logo() &&
is_front_page() || is_home() )
How can i add as a part of statement the condition of OR is_page('destination') and include all childs of that page? so e.g. Ive got page
Destination
+ New York
+ Warsaw
+ Dublin
+ Dubai
and i would like to cover all those pages. I've tried doing something like:
|| is_page('destination') || is_child('destination') but simply it doesnt work..
thanks!
You could use this
function is_child($pageID) { // In functions.php
global $post;
if( is_page() && ($post->post_parent==$pageID) ) {
return true;
} else {
return false;
}
}
if(is_child(123)) { // in your template
echo "Child page of 123";
}
Hello, professional coders.
Sorry for my poor English, and I know nothing about code.
I want to add permlink to each post item from blog-layout.php file.
It is related to category page.
I found post loop in there, and want to know how to add permalink.
reference site : http://blog.lgchem.com/category/company-story/
Since I am not a developer, step-by-step instructions would truly be appreciated.
// Start the main loop
while ( have_posts() ): the_post();
// Set the time stamps for timeline month/year check
$alignment_class = '';
if( $blog_layout == 'timeline' ) {
$post_timestamp = get_the_time( 'U' );
$post_month = date( 'n', $post_timestamp );
$post_year = get_the_date( 'o' );
$current_date = get_the_date( 'o-n' );
// Set the correct column class for every post
if( $post_count % 2 ) {
$alignment_class = 'fusion-left-column';
} else {
$alignment_class = 'fusion-right-column';
}
// Set the timeline month label
if ( $prev_post_month != $post_month ||
$prev_post_year != $post_year
) {
if( $post_count > 1 ) {
echo '</div>';
}
echo sprintf( '<h3 class="fusion-timeline-date">%s</h3>', get_the_date( Avada()->settings->get( 'timeline_date_format' ) ) );
echo '<div class="fusion-collapse-month">';
}
}
// Set the has-post-thumbnail if a video is used. This is needed if no featured image is present.
$thumb_class = '';
if ( get_post_meta( get_the_ID(), 'pyre_video', true ) ) {
$thumb_class = ' has-post-thumbnail';
}
$post_classes = sprintf( '%s %s %s post fusion-clearfix', $post_class, $alignment_class, $thumb_class );
ob_start();
post_class( $post_classes );
$post_classes = ob_get_clean();
// post item
echo sprintf( '<div id="post-%s" %s>', get_the_ID(), $post_classes);
// Add an additional wrapper for grid layout border
if ( $blog_layout == 'grid' ) {
echo '<div class="fusion-post-wrapper">';
}
// Get featured images for all but large-alternate layout
if ( Avada()->settings->get( 'featured_images' ) &&
$blog_layout == 'large-alternate'
) {
get_template_part( 'new-slideshow' );
}
// Get the post date and format box for alternate layouts
if ( $blog_layout == 'large-alternate' ||
$blog_layout == 'medium-alternate'
) {
echo '<div class="fusion-date-and-formats">';
/**
* avada_blog_post_date_adn_format hook
*
* #hooked avada_render_blog_post_date - 10 (outputs the HTML for the date box)
* #hooked avada_render_blog_post_format - 15 (outputs the HTML for the post format box)
*/
do_action( 'avada_blog_post_date_and_format' );
echo '</div>';
}
// Get featured images for all but large-alternate layout
if ( Avada()->settings->get( 'featured_images' ) &&
$blog_layout != 'large-alternate'
) {
get_template_part( 'new-slideshow' );
}
// post-content-wrapper only needed for grid and timeline
if ( $blog_layout == 'grid' ||
$blog_layout == 'timeline'
) {
echo '<div class="fusion-post-content-wrapper">';
}
// Add the circles for timeline layout
if ( $blog_layout == 'timeline' ) {
echo '<div class="fusion-timeline-circle"></div>';
echo '<div class="fusion-timeline-arrow"></div>';
}
echo '<div class="fusion-post-content">';
// Render the post title
echo avada_render_post_title( get_the_ID() );
// Render post meta for grid and timeline layouts
if ( $blog_layout == 'grid' ||
$blog_layout == 'timeline'
) {
echo avada_render_post_metadata( 'grid_timeline' );
if ( ( Avada()->settings->get( 'post_meta' ) && ( ! Avada()->settings->get( 'post_meta_author' ) || ! Avada()->settings->get( 'post_meta_date' ) || ! Avada()->settings->get( 'post_meta_cats' ) || ! Avada()->settings->get( 'post_meta_tags' ) || ! Avada()->settings->get( 'post_meta_comments' ) || ! Avada()->settings->get( 'post_meta_read' ) ) ) &&
Avada()->settings->get( 'excerpt_length_blog' ) > 0
) {
echo '<div class="fusion-content-sep"></div>';
}
// Render post meta for alternate layouts
} elseif( $blog_layout == 'large-alternate' ||
$blog_layout == 'medium-alternate'
) {
echo avada_render_post_metadata( 'alternate' );
}
echo '<div class="fusion-post-content-container">';
/**
* avada_blog_post_content hook
*
* #hooked avada_render_blog_post_content - 10 (outputs the post content wrapped with a container)
*/
do_action( 'avada_blog_post_content' );
do_action( 'avada_blog_post_date_and_format' );
echo '</div>';
echo '</div>'; // end post-content
if( $blog_layout == 'medium' ||
$blog_layout == 'medium-alternate'
) {
echo '<div class="fusion-clearfix"></div>';
}
// Render post meta data according to layout
if ( ( Avada()->settings->get( 'post_meta' ) && ( ! Avada()->settings->get( 'post_meta_author' ) || ! Avada()->settings->get( 'post_meta_date' ) || ! Avada()->settings->get( 'post_meta_cats' ) || ! Avada()->settings->get( 'post_meta_tags' ) || ! Avada()->settings->get( 'post_meta_comments' ) || ! Avada()->settings->get( 'post_meta_read' ) ) ) ) {
echo '<div class="fusion-meta-info">';
if ( $blog_layout == 'grid' ||
$blog_layout == 'timeline'
) {
// Render read more for grid/timeline layouts
echo '<div class="fusion-alignleft">';
if ( ! Avada()->settings->get( 'post_meta_read' ) ) {
$link_target = '';
if( fusion_get_page_option( 'link_icon_target', get_the_ID() ) == 'yes' ||
fusion_get_page_option( 'post_links_target', get_the_ID() ) == 'yes' ) {
$link_target = ' target="_blank"';
}
echo sprintf( '<a href="%s" class="fusion-read-more"%s>%s</a>', get_permalink(), $link_target, apply_filters( 'avada_blog_read_more_link', __( 'Read More', 'Avada' ) ) );
}
echo '</div>';
// Render comments for grid/timeline layouts
echo '<div class="fusion-alignright">';
if ( ! Avada()->settings->get( 'post_meta_comments' ) ) {
if( ! post_password_required( get_the_ID() ) ) {
comments_popup_link('<i class="fusion-icon-bubbles"></i> ' . __( '0', 'Avada' ), '<i class="fusion-icon-bubbles"></i> ' . __( '1', 'Avada' ), '<i class="fusion-icon-bubbles"></i> ' . '%' );
} else {
echo sprintf( '<i class="fusion-icon-bubbles"></i> %s', __( 'Protected', 'Avada' ) );
}
}
echo '</div>';
} else {
// Render all meta data for medium and large layouts
if ( $blog_layout == 'large' || $blog_layout == 'medium' ) {
echo avada_render_post_metadata( 'standard' );
}
// Render read more for medium/large and medium/large alternate layouts
echo '<div class="fusion-alignright">';
if ( ! Avada()->settings->get( 'post_meta_read' ) ) {
$link_target = '';
if( fusion_get_page_option( 'link_icon_target', get_the_ID() ) == 'yes' ||
fusion_get_page_option( 'post_links_target', get_the_ID() ) == 'yes' ) {
$link_target = ' target="_blank"';
}
echo sprintf( '<a href="%s" class="fusion-read-more"%s>%s</a>', get_permalink(), $link_target, __( 'Read More', 'Avada' ) );
}
echo '</div>';
}
echo '</div>'; // end meta-info
}
if ( $blog_layout == 'grid' ||
$blog_layout == 'timeline'
) {
echo '</div>' ;
// end post-content-wrapper
}
if ( $blog_layout == 'grid' ) {
echo '</div>'; // end post-wrapper
}
echo '</div>'; // end post
// post item
// Adjust the timestamp settings for next loop
if ( $blog_layout == 'timeline' ) {
$prev_post_timestamp = $post_timestamp;
$prev_post_month = $post_month;
$prev_post_year = $post_year;
$post_count++;
}
endwhile; // end have_posts()
if ( $blog_layout == 'timeline' &&
$post_count > 1
) {
echo '</div>';
}
echo '</div>'; // end posts-container
There's several approaches you could do.
You could either link it to whatever you like in Wordpress CMS backend.
If you want to modify the source code for all the items, you could wrap your div in something like this:
<a href="<?php the_permalink(); ?>">
I would recommend that you have a child theme if you're going to change the source, in that case when your theme (Avada) gets updated, your changes wont disappear.
Read more on permalinks on Wordpress docs:
https://codex.wordpress.org/Function_Reference/the_permalink
https://codex.wordpress.org/Using_Permalinks
There is breadcrumbs on product page and product title just below them. It's too much for one line and I want to hide current crumb like this:
Home->Catalog->Category->Subcategory->
H1 Product Title
I found in woocommerce/templates/global/breadcrumb.php the part for $crumb. All is a link, but last is a simple text.
foreach ( $breadcrumb as $key => $crumb ) {
echo $before;
if ( ! empty( $crumb[1] ) && sizeof( $breadcrumb ) !== $key + 1 ) {
echo '' . esc_html( $crumb[0] ) . '';
} else {
echo esc_html( $crumb[0] ); // Just replace $crumb here for empty ''
}
echo $after;
if ( sizeof( $breadcrumb ) !== $key + 1 ) {
echo $delimiter;
}
}
Add This CSS in Your Active theme.
.woocommerce-breadcrumb { display:none !important; }
Enjoy.!
I need advice,
I've installed facebook/google+ on my wordpress category pages.
For example: http://www.sandrophoto.com/category/famous-photographers/
First page has allot of likes, but second and third page only few. This pushed me to think, maybe I should unite those pages into one.
And instead of having separate 'like button' for urls, I would point button only to first page.
http://www.sandrophoto.com/category/famous-photographers/page/2/
http://www.sandrophoto.com/category/famous-photographers/page/3/
Does this make sense?
Any ideas how to implement this? I use this currently:
//get current archives url for fb like and open graph
function get_current_archive_link( $paged = true ) {
$link = false;
if ( is_front_page() ) {
$link = home_url( '/' );
} else if ( is_home() && "page" == get_option('show_on_front') ) {
$link = get_permalink( get_option( 'page_for_posts' ) );
} else if ( is_tax() || is_tag() || is_category() ) {
$term = get_queried_object();
$link = get_term_link( $term, $term->taxonomy );
} else if ( is_post_type_archive() ) {
$link = get_post_type_archive_link( get_post_type() );
} else if ( is_author() ) {
$link = get_author_posts_url( get_query_var('author'), get_query_var('author_name') );
} else if ( is_archive() ) {
if ( is_date() ) {
if ( is_day() ) {
$link = get_day_link( get_query_var('year'), get_query_var('monthnum'), get_query_var('day') );
} else if ( is_month() ) {
$link = get_month_link( get_query_var('year'), get_query_var('monthnum') );
} else if ( is_year() ) {
$link = get_year_link( get_query_var('year') );
}
}
}
if ( $paged && $link && get_query_var('paged') > 1 ) {
global $wp_rewrite;
if ( !$wp_rewrite->using_permalinks() ) {
$link = add_query_arg( 'paged', get_query_var('paged'), $link );
} else {
$link = user_trailingslashit( trailingslashit( $link ) . trailingslashit( $wp_rewrite->pagination_base ) . get_query_var('paged'), 'archive' );
}
}
return $link;
}
For both platforms allow you to specify the URL you want Liked/Plused, rather than them trying to determine the URL from the page location and or other meta data. Just specify the same URL in the plugin code to be used on both pages.
Facebook HTML5 version of the plugin would need to be updated like:
<div class="fb-like" data-href="{your URL}"></div>
and Plus 1
<g:plusone annotation="inline" href="{your URL}"></g:plusone>