Wordpress Functions.php Advice - php

I am looking to take away some hyperlinks from the functions.php folder on my wordpress website.
I do not want any of the below to be clickable, only the text show. Is this possible to do?
} elseif ( is_tag() ) {
echo "<li typeof='v:Breadcrumb'>" . single_tag_title( '', false ) . '</li>';
} elseif ( is_day() ) {
echo __( "Archive", 'thrive' ) . ": ";
the_time( 'F jS, Y' );
echo '</li>';
} elseif ( is_month() ) {
echo __( "Archive", 'thrive' ) . ": ";
the_time( 'F, Y' );
echo '</li>';
} elseif ( is_year() ) {
echo __( "Archive", 'thrive' ) . ": ";
the_time( 'Y' );
echo '</li>';
} elseif ( is_author() ) {
echo __( "Author's archive", 'thrive' ) . ": ";
echo '</li>';
} elseif ( isset( $_GET['paged'] ) && ! empty( $_GET['paged'] ) ) {
echo __( "Archive", 'thrive' ) . ": ";
echo '';
} elseif ( is_search() ) {
echo __( "Search results", 'thrive' ) . ": ";
} elseif ( is_archive() ) {
echo __( "Archive", 'thrive' ) . ": ";
}
I appreciate any tips!
Many thanks!

Related

Wordpress child theme - Shopisle changing big title

I found this thread which describes exactly my problem but I tried the solution and it doesn't work.
Here is my front-page.php code:
<?php
get_header();
/* Wrapper start */
echo '<div class="main">';
$big_title = get_stylesheet_directory() . '/inc/shop_isle_big_title_section.php';
load_template( apply_filters( 'shop-isle-subheader', $big_title ) );
And here my shop_isle_big_title_section.php:
<?php
/**
* Big title section
*
* #package ShopIsle
* #since 1.0.0
*/
$shop_isle_homepage_slider_shortcode = get_theme_mod( 'shop_isle_homepage_slider_shortcode' );
$shop_isle_big_title_hide = get_theme_mod( 'shop_isle_big_title_hide' );
if ( isset( $shop_isle_big_title_hide ) && $shop_isle_big_title_hide != 1 ) {
echo '<section id="home" class="home-section home-parallax home-fade' . ( empty( $shop_isle_homepage_slider_shortcode ) ? ' home-full-height' : ' home-slider-plugin' ) . '">';
} elseif ( is_customize_preview() ) {
echo '<section id="home" class="home-section home-parallax home-fade shop_isle_hidden_if_not_customizer' . ( empty( $shop_isle_homepage_slider_shortcode ) ? ' home-full-height' : ' home-slider-plugin' ) . '">';
}
if ( ! empty( $shop_isle_homepage_slider_shortcode ) ) {
echo do_shortcode( $shop_isle_homepage_slider_shortcode );
} else {
$shop_isle_big_title_image = get_theme_mod( 'shop_isle_big_title_image', get_template_directory_uri() . '/assets/images/background-video.jpg' );
$shop_isle_big_title_title = get_theme_mod( 'shop_isle_big_title_title', 'Test' );
$shop_isle_big_title_subtitle = get_theme_mod( 'shop_isle_big_title_subtitle', __( 'WooCommerce Theme', 'shop-isle' ) );
if ( ! empty( $shop_isle_big_title_image ) ) {
echo '<div class="hero-slider">';
echo '<ul class="slides">';
//echo '<li class="bg-dark" style="background-image:url(' . esc_url( $shop_isle_big_title_image ) . ')">';
echo '<div class="home-slider-overlay"></div>';
echo '<div class="hs-caption">';
echo '<div class="caption-content">';
if ( ! empty( $shop_isle_big_title_title ) ) {
echo '<h1 class="hs-title-size-4 font-alt mb-30">Test Custom</h1>';
} elseif ( is_customize_preview() ) {
echo '<h1 class="hs-title-size-4 font-alt mb-30"></h1>';
}
if ( ! empty( $shop_isle_big_title_subtitle ) ) {
echo '<div class="hs-title-size-1 font-alt mb-40">Custom Sub</div>';
} elseif ( is_customize_preview() ) {
echo '<div class="hs-title-size-1 font-alt mb-40"></div>';
}
shop_isle_big_title_section_display_button();
echo '</div><!-- .caption-content -->';
echo '</div><!-- .hs-caption -->';
echo '</li><!-- .bg-dark -->';
echo '</ul><!-- .slides -->';
echo '</div><!-- .hero-slider -->';
}
}// End if().
echo '</section >';
As you can see the big title should normally display the text "Test Custom" and "Custom sub" and with no background, which it doesn't. I hope someone can see what I did wrong. What I want is that my changes are showed, which it does not in this case (yes my child theme is working correctly).

full path in breadcrumbs wordpress

I want to take a full path in bread crumbs in the wordpress template
Now displays only the home page and category
I want the home - category - the title of the article with the link to this page, with a working schema markup
now the code looks like this
version Wordpress 4.8.1
function barcelona_breadcrumb() {
if ( barcelona_get_option( 'show_breadcrumb' ) != 'on' ) {
return;
}
$barcelona_post_type = is_single() ? get_post_type() : NULL;
$barcelona_sep_icon = '';
$barcelona_items = '';
if ( ( is_single() && $barcelona_post_type == 'post' && ! is_attachment() ) || is_category() ) {
$barcelona_categories = is_category() ? array() : get_the_category();
$barcelona_current_cat = $barcelona_last_cat = is_category() ? get_queried_object() : $barcelona_categories[0];
$barcelona_counter = 3;
while ( $barcelona_current_cat->category_parent != '0' ) {
$barcelona_current_cat = get_category( $barcelona_current_cat->category_parent );
$barcelona_items = $barcelona_sep_icon .'<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="'. esc_url( get_category_link( $barcelona_current_cat ) ) .'"><span itemprop="name">'. esc_html( $barcelona_current_cat->name ) .'</span></a><meta itemprop="position" content="%'. $barcelona_counter .'%" /></li>'. $barcelona_items;
$barcelona_counter++;
}
$barcelona_items .= $barcelona_sep_icon .'<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><'. ( is_category() ? 'span' : 'a href="'. esc_url( get_category_link( $barcelona_last_cat ) ) .'"' ) .' itemprop="item"><span itemprop="name">'. esc_html( $barcelona_last_cat->name ) .'</span></'. ( is_category() ? 'span' : 'a' ) .'><meta itemprop="position" content="%2%" /></li>';
if ( $barcelona_counter > 3 ) {
$barcelona_arr = array_reverse( range( 2, $barcelona_counter - 1 ) );
foreach( $barcelona_arr as $k => $v ) {
$barcelona_items = str_replace( 'itemprop="position" content="%'. intval( $k + 2 ) .'%"', 'itemprop="position" content="'. intval( $v ) .'"', $barcelona_items );
}
} else {
$barcelona_items = str_replace( 'content="%2%"', 'content="2"', $barcelona_items );
}
} else if ( is_archive() || is_search() ) {
$barcelona_title = is_search() ? esc_html__( 'Search Results', 'barcelona' ) : esc_html( get_the_archive_title() );
if ( is_author() ) {
$barcelona_title = esc_html__( 'Author Archive', 'barcelona' );
} else if ( is_year() ) {
$barcelona_title = esc_html__( 'Yearly Archive', 'barcelona' );
} else if ( is_month() ) {
$barcelona_title = esc_html__( 'Monthly Archive', 'barcelona' );
} else if ( is_day() ) {
$barcelona_title = esc_html__( 'Daily Archive', 'barcelona' );
} else if ( is_tag() ) {
$barcelona_title = esc_html__( 'Tag Archive', 'barcelona' );
}
$barcelona_items .= $barcelona_sep_icon .'<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><span itemprop="item"><span itemprop="name">'. $barcelona_title .'</span></span><meta itemprop="position" content="2" /></li>';
}
$barcelona_items = '<li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a itemprop="item" href="'. esc_url( home_url( '/' ) ) .'">'. esc_html__( 'Home', 'barcelona' ) .'</a><meta itemprop="position" content="1" /></li>'. $barcelona_items;
echo '<div class="breadcrumb-wrapper"><div class="container"><ol itemscope itemtype="http://schema.org/BreadcrumbList" class="breadcrumb">'. $barcelona_items .'</ol></div></div>';
}
Thanks!
Try with below code put below code in functions.php
function the_breadcrumbs() {
global $post;
if (!is_home()) {
echo "<a href='";
echo get_option('home');
echo "'>";
echo "Site's name here";
echo "</a>";
if (is_category() || is_single()) {
echo " > ";
$cats = get_the_category( $post->ID );
foreach ( $cats as $cat ){
echo $cat->cat_name;
echo " > ";
}
if (is_single()) {
the_title();
}
} elseif (is_page()) {
if($post->post_parent){
$anc = get_post_ancestors( $post->ID );
$anc_link = get_page_link( $post->post_parent );
foreach ( $anc as $ancestor ) {
$output = " > ".get_the_title($ancestor)." > ";
}
echo $output;
the_title();
} else {
echo ' > ';
echo the_title();
}
}
}
elseif (is_tag()) {single_tag_title();}
elseif (is_day()) {echo"Archive: "; the_time('F jS, Y'); echo'</li>';}
elseif (is_month()) {echo"Archive: "; the_time('F, Y'); echo'</li>';}
elseif (is_year()) {echo"Archive: "; the_time('Y'); echo'</li>';}
elseif (is_author()) {echo"Author's archive: "; echo'</li>';}
elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "Blogarchive: "; echo'';}
elseif (is_search()) {echo"Search results: "; }
}
Put below code in header.php
if(function_exists('the_breadcrumbs')) the_breadcrumbs();

php operator without spaces

I have this shopkeeper running in Wordpress. And I want to change the colon to parentheses but it gets weird , I don't want spaces between it just like this " (€5,50).
I've been trying to fix this problem for almost a day.
really hope to see any answers.
here is the html : gyazo.com/f05c00f01d2522aa962d90f5c0fcc5ea
method function :
function wc_cart_totals_shipping_method_label( $method ) {
$label = $method->label;
if ( $method->cost > 0 ) {
if ( WC()->cart->tax_display_cart == 'excl' ) {
$label .= ': ' . wc_price( $method->cost );
if ( $method->get_shipping_tax() > 0 && WC()->cart->prices_include_tax ) {
$label .= ' <small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';
}
} else {
$label .= '(' . wc_price( $method->cost + $method->get_shipping_tax() ).')';
if ( $method->get_shipping_tax() > 0 && ! WC()->cart->prices_include_tax ) {
$label .= ' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>';
}
}
} elseif ( $method->id !== 'free_shipping' ) {
$label .= ' (' . __( 'Free', 'woocommerce' ) . ')';
}
return apply_filters( 'woocommerce_cart_shipping_method_full_label', $label, $method );
}
code where I print :
<select name="shipping_method[<?php echo $index; ?>]" data-index="<?php echo $index; ?>" id="shipping_method_<?php echo $index; ?>" class="shipping_method">
<?php foreach ( $available_methods as $method ) : ?>
<option value="<?php echo esc_attr( $method->id ); ?>" <?php selected( $method->id, $chosen_method ); ?>><?php echo wp_kses_post( wc_cart_totals_shipping_method_label( $method ) ); ?></option>
<?php endforeach; ?>
</select>
Before the result try to add this:
$label = '(€'.preg_replace("/\([\s]+?/", "", str_replace(array('€', ' '), '', $label));
First use str_replace to remove html entities, seconds use a regex to remove all whitespaces after the ( and finally append at the start of the string "(€"

echo 'archives : ' . single_cat_title(); displays wrong output

My PHP code is giving the wrong output I require.
<h4>
<?php
if ( is_category() ) {
echo 'archives : ' . single_cat_title();
} elseif ( is_tag() ) {
echo single_tag_title() . ' : archives';
} elseif ( is_author() ) {
the_post();
echo 'Author archives : ' . get_the_author();
rewind_posts();
} elseif ( is_day() ) {
echo 'Daily archives : ' . get_the_date();
} elseif ( is_month() ) {
echo 'Monthly archives : ' . get_the_date('F Y');
} elseif ( is_year() ) {
echo 'Yearly archives : ' . get_the_date('Y');
} else {
echo 'Archives:';
}
?>
</h4>
Gives out business archives :, but desire it to be archives : business.
How do I fix this, please
Thanks
Steven
single_cat_title('archive : ');
I found my answer, thanks for your help.

I want to add "Category" to my WP breadcrumbs

I have a premium WordPress theme which has breadcrumbs by default, but it does not show Category (and Sub-Category) item when on post page: Home > Category > Sub-Category > Post Title
Instead it just displays like this: Home > Post Title
This is the function which handles breadcrumbs:
(I marked the part of the code that I think is important with this sign, to save you time: ==========>>)
// BREADCRUMBS
if ( ! function_exists( 'ishyoboy_get_breadcrumbs' ) ) {
function ishyoboy_get_breadcrumbs() {
global $ish_options, $ish_woo_id;
$return = '';
$return .= '<div class="ish-pb-breadcrumbs"><div><div>' . "\n";
if ( ! is_front_page() ) {
if ( function_exists('is_woocommerce') ) {
if ( !is_woocommerce() && !is_woocommerce_page() ){
$return .= '<a class="ish-pb-breadcrumbs-home" href="';
$return .= home_url();
$return .= '">';
$return .= '<span>' . __( 'Home', 'ishyoboy' ) . '</span>';
$return .= "</a> > ";
}
}
else{
$return .= '<a class="ish-pb-breadcrumbs-home" href="';
$return .= home_url();
$return .= '">';
$return .= '<span>' . __( 'Home', 'ishyoboy' ) . '</span>';
$return .= "</a> > ";
}
}
else {
$return .= '<span class="ish-pb-breadcrumbs-home">';
$return .= '<span>' . __( 'Home', 'ishyoboy' ) . '</span>';
$return .= "</span>";
}
if ( !is_front_page() && is_home() ) {
global $page;
$return .= $page->post_title;
}
if ( is_archive() && 'post' == get_post_type() && ! is_category() && ( !function_exists('is_woocommerce') || !is_woocommerce() ) ) {
$hpage = get_page( get_option( 'page_for_posts' ) );
if ( 'page' == get_option('show_on_front') && isset($hpage) && '' != $hpage ){
$return .= get_page_parents($hpage->ID, TRUE, ' > ', FALSE );
}
if ( is_day() ) :
$return .= sprintf( __( 'Daily Archives: %s', 'ishyoboy' ), '<span>' . get_the_date() . '</span>' );
elseif ( is_month() ) :
$return .= sprintf( __( 'Monthly Archives: %s', 'ishyoboy' ), '<span>' . get_the_date( _x( 'F Y', 'monthly archives date format', 'ishyoboy' ) ) . '</span>' );
elseif ( is_year() ) :
$return .= sprintf( __( 'Yearly Archives: %s', 'ishyoboy' ), '<span>' . get_the_date( _x( 'Y', 'yearly archives date format', 'ishyoboy' ) ) . '</span>' );
else :
$return .= __( 'Archives', 'ishyoboy' );
endif;
}
else if ( is_archive() && 'post' != get_post_type() && ( !function_exists('is_woocommerce') || !is_woocommerce() ) ) {
$type = get_post_type( get_the_ID() );
$obj = get_post_type_object( $type );
if ( is_object( $obj ) ){
$return .= $obj->labels->name;
}
}
if ( (is_category() || is_single()) && ( ( !function_exists('is_woocommerce_page') || !function_exists('is_woocommerce' ) ) || ( !is_woocommerce() && !is_woocommerce_page() ) ) ) {
$post_id = ish_get_the_ID();
$post_type = get_post_type();
switch ($post_type){
case 'portfolio-post' :
$terms = get_the_terms($post_id, 'portfolio-category' );
$term = ( ! empty( $terms ) ) ? array_pop($terms) : '';
if (isset($ish_options['page_for_custom_post_type_portfolio-post']) && '-1' != $ish_options['page_for_custom_post_type_portfolio-post']){
$portfolio_page = get_page($ish_options['page_for_custom_post_type_portfolio-post']);
$separator = " > ";
$return .= ''.$portfolio_page->post_title.'' . $separator;
}
if ( ! empty( $term ) ){
$return .= get_term_parents($term->term_id, 'portfolio-category', TRUE, ' > ', FALSE );
}
break;
// from here ==========>>
case 'post' :
if ( is_category() ){
global $cat;
$category = get_category($cat);
if ( $category->parent && ( $category->parent != $category->term_id ) ){
$return .= get_category_parents($category->parent, TRUE, ' > ', FALSE );
}
$return .= single_cat_title('', false);
}
else{
$category = get_the_category();
if ( is_object( $category ) ){
$ID = $category[0]->cat_ID;
$return .= get_category_parents($ID, TRUE, ' > ', FALSE );
}
}
break;
// to here ==========>>
default :
$type = get_post_type( get_the_ID() );
$obj = get_post_type_object( $type );
if ( is_object( $obj ) ){
$return .= '' . $obj->labels->name . ' > ';
}
}
}
else if ( ( function_exists('is_woocommerce_page') && function_exists('is_woocommerce') ) && (is_woocommerce() || is_woocommerce_page() )){
ob_start();
woocommerce_breadcrumb(array(
'delimiter' => ' > ',
'wrap_before' => '',
'wrap_after' => '',
'before' => '',
'after' => '',
'home' => '<span class="ish-pb-breadcrumbs-home"><span>' . _x( 'Home', 'breadcrumb', 'woocommerce' ) . '</span></span>',
));
$return .= ob_get_contents();
ob_end_clean();
ob_end_flush();
}
else if (is_tax()){
if (is_tax('portfolio-category')){
$current_term = get_queried_object();
if ( !empty($current_term) ){
//var_dump($current_term);
if (isset($ish_options['page_for_custom_post_type_portfolio-post']) && '-1' != $ish_options['page_for_custom_post_type_portfolio-post']){
$portfolio_page = get_page($ish_options['page_for_custom_post_type_portfolio-post']);
$separator = " > ";
$return .= ''.$portfolio_page->post_title.'' . $separator;
}
if ($current_term->parent != 0 ){
$return .= get_term_parents($current_term->parent, 'portfolio-category', TRUE, ' > ', FALSE );
}
$return .= $current_term->name;
}
}
}
else if (is_page()){
global $post;
if ($post->post_parent != 0 ){
$return .= get_page_parents($post->post_parent, TRUE, ' > ', FALSE );
}
}
if (!function_exists('is_woocommerce_page') || !is_woocommerce_page()){
if(is_single()) {$return .= get_the_title();}
if(is_page()) {
global $post;
$frontpage = get_option('page_on_front');
if ( $frontpage && $frontpage == $post->ID){
/*$return .= '<a class="home" href="';
$return .= home_url();
$return .= '">';
$return .= '<span>' . __( 'Home', 'ishyoboy' ) . '</span>';
$return .= "</a>";*/
} else {
$return .= get_the_title();
}
}
if(is_tag()){ $return .= __( 'Tag: ', 'ishyoboy' ) . single_tag_title('',FALSE); }
if(is_404()){ $return .= __( '404 - Page not Found', 'ishyoboy' ); }
if(is_search()){ $return .= __( 'Search', 'ishyoboy' ); }
if(is_year()){ $return .= get_the_time('Y'); };
}
$return .= '</div></div></div>';
return $return;
}
}
if ( !function_exists('the_post_thumbnail_caption') ) {
function the_post_thumbnail_caption(){
$thumb = get_post_thumbnail_id();
if ( ! empty( $thumb ) ){
$thumb_object = get_post( $thumb );
if ( ! empty( $thumb_object ) ) {
echo '<div class="wp-caption"><p class="wp-caption-text">' . $thumb_object->post_excerpt . '</p></div>';
}
}
}
}
if ( !function_exists('get_the_post_thumbnail_caption') ) {
function get_the_post_thumbnail_caption(){
$thumb = get_post_thumbnail_id();
if ( ! empty( $thumb ) )
return get_post( $thumb )->post_excerpt;
return null;
}
}
if ( ! function_exists( 'ishyoboy_activate_fancybox_on_blog_single' ) ) {
function ishyoboy_activate_fancybox_on_blog_single() {
if ( is_singular() && !is_singular( 'product' ) ){
?>
<script type="text/javascript">
jQuery(document).ready(function($){
var thumbnails = jQuery("a:has(img)").not(".nolightbox").filter( function() { return /\.(jpe?g|png|gif|bmp)$/i.test(jQuery(this).attr('href')) });
if ( thumbnails.length > 0){
thumbnails.addClass( 'openfancybox-image' ).attr( 'rel', 'fancybox-post-image-<?php the_ID() ?>');
}
});
</script>
<?php
}
}
}
add_action( 'wp_head', 'ishyoboy_activate_fancybox_on_blog_single' );
if ( ! function_exists( 'ishyoboy_dummy_functions' ) ) {
function ishyoboy_dummy_functions() {
if ( false ) {
posts_nav_link();
wp_link_pages();
$args = '';
add_theme_support( 'custom-header', $args );
add_theme_support( 'custom-background', $args );
}
}
}
And then I've made a change in code which generated the desired change - Category appeared in breadcrumbs: Home > Category > Sub-Category > Post Title
But on the Category archive page breadcrumbs look like this: Home > Category > Category
Live example: http://pigtelligent.com/science/
The change I've made in above-mentioned code:
case 'post' :
$terms = get_the_terms($post_id, 'category' );
$term = ( ! empty( $terms ) ) ? array_pop($terms) : '';
if ( ! empty( $term ) ){
$return .= get_term_parents($term->term_id, 'category', TRUE, ' > ', FALSE );
}
I know that for someone smarter this should be easy, but I've spent whole day trying to figure this out, so can you please help me? :)
Categories can get tricky fast as posts can have multiple categories, and category landing pages can access a lot of meta which can get misleading. Make sure you've reviewed the Template Hierarchy page on the codex and you've got a firm understanding of how WP handles taxonomy.
Use What The File to find out what template you're actually on as you might not be on a category page, causing is_category() to return false. You could be on a single (as the if statement wrapping the logic you pointed out is checking is_category() || is_single()), or you might need to add a check for is_archive().
My best suggestion is to figure out if you're on a category page first, then stop all that extra logic and just spit out the category's name. Not too much help, I know, but hopefully that'll point you in the right direction
function the_breadcrumb() {
global $post;
echo '<ul id="breadcrumbs">';
if (!is_home()) {
echo '<li><a href="';
echo get_option('home');
echo '">';
echo 'Home';
echo '</a></li><li class="separator"> / </li>';
if (is_category() || is_single()) {
echo '<li>';
the_category(' </li><li class="separator"> / </li><li> ');
if (is_single()) {
echo '</li><li class="separator"> / </li><li>';
the_title();
echo '</li>';
}
} elseif (is_page()) {
if($post->post_parent){
$anc = get_post_ancestors( $post->ID );
$title = get_the_title();
foreach ( $anc as $ancestor ) {
$output = '<li>'.get_the_title($ancestor).'</li> <li class="separator">/</li>';
}
echo $output;
echo '<strong title="'.$title.'"> '.$title.'</strong>';
} else {
echo '<li><strong> '.get_the_title().'</strong></li>';
}
}
}
elseif (is_tag()) {single_tag_title();}
elseif (is_day()) {echo"<li>Archive for "; the_time('F jS, Y'); echo'</li>';}
elseif (is_month()) {echo"<li>Archive for "; the_time('F, Y'); echo'</li>';}
elseif (is_year()) {echo"<li>Archive for "; the_time('Y'); echo'</li>';}
elseif (is_author()) {echo"<li>Author Archive"; echo'</li>';}
elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "<li>Blog Archives"; echo'</li>';}
elseif (is_search()) {echo"<li>Search Results"; echo'</li>';}
echo '</ul>';
}
?>
Get using: <?php the_breadcrumb(); ?>

Categories