Change the Woocommerce breadcrumb link - php

I'm using the following snippet to change the URL but I want to make it dynamic rather than hard coding a link in.
add_filter( 'woocommerce_breadcrumb_home_url', 'woo_custom_breadrumb_home_url' );
function woo_custom_breadrumb_home_url() {
return 'http://woothemes.com';
}
I tried the following which not only breaks the link but it appears in the top of the screen.
$breadcrumb = bloginfo('url');
add_filter( 'woocommerce_breadcrumb_home_url', 'woo_custom_breadrumb_home_url' );
function woo_custom_breadrumb_home_url() {
return '$breadcrumb';
}
How can I make the Home link dynamic?

You can try
return home_url();
This should give you the same address as bloginfo('url')

Related

Add custom canonical for front page - Yoast

I want to add a custom url for the front page using YOAST. I'm trying this approach but it doesn't do anything, can you help me?
function design_canonical($url) {
global $post;
$url == ( 'www.cator.com/cator/');
}
add_filter( 'wpseo_canonical', 'design_canonical' );
any idea where is the problem?
thanks
You first need to check if your page is home or not which you can check through is_home()
function design_canonical($url) {
if (is_home()) {
return 'your-custom-url.com'; //Enter here your custom url
} else {
return $url;
}
}
add_filter( 'wpseo_canonical', 'design_canonical' );

WordPress - Custom Product Search Option in Home Page

I've a WordPress website and am trying to add a custom search option in the website's home page as well in the header section. Unfortunately I can't see any option to include it from the website's dashboard and decided to follow the link to create a custom one as follows:
Tutorial Link - Custom Search
and this is the code that I've tried same as the tutorial:
add_action('tickercontainer','add_search_to_footer'); //Guessinghere I've to declare the div class
function add_search_to_footer() {
get_search_form();
}
function SearchFilter($query) {
if ( !is_admin() && $query->is_search ) {
$query->set('post_type', 'post'); //OR USE 'PRODUCT'
}
return $query;
}
add_filter('pre_get_posts','SearchFilter');
function storefront_search_form_modify( $html ) {
return str_replace( array('Search …','Search'), array('WooCommerce Hooks, Storefront Theme, Google AdWords...','Search Article'), $html );
}
add_filter( 'get_search_form', 'storefront_search_form_modify' );
function new_nav_menu_items($items) {
$searchicon = '<li class="search"><i class="fa fa-search" aria-hidden="true"></i></li>';
$items = $items . $searchicon;
return $items;
}
add_filter( 'wp_nav_menu_additional-resources_items', 'new_nav_menu_items' );
Though I am not sure what I am missing here and would expect some ideas to implement in an appropriate way.
Note: Right now, after including the code above, I can't see the search option in the website.

how to remove read more after call the_content function in wordpress?

I want to remove read-more link after calling the_content() function of wordpress. I want only to show content of each post in a loop and read-more link is redundant.
I try this code but read-more link remains after post content:
add_filter( 'the_content_more_link', 'disable_more_link', 10, 2 );
function disable_more_link( $more_link, $more_link_text ) {
return;
}
where I can find the code that adds this read-more link after the content?
You can use a filter to remove the read-more link from content. I have updated your filter. Please try it, It's working fine.
function disable_more_link( $link ) {
$link = preg_replace( '|#more-[0-9]+|', '', '' );
return $link;
}
add_filter( 'the_content_more_link', 'disable_more_link', 10, 2 );
More info
function new_excerpt_more($more) {
return '...';
}
add_filter('excerpt_more', 'new_excerpt_more');

Add text on wordpress admin login page

I want to add a text in admin login page, i searched a lot about this but can't find any thing else a plugin (its my last option).
I also use this filter:
function my_login_logo_url_title() {
return 'Your Site Name and Info';
}
add_filter( 'login_headertitle', 'my_login_logo_url_title' );
But nothing happens; is there any other hook or filter?
Try this :
add_filter( 'login_message', 'my_login_logo_url_title' );
function my_login_logo_url_title() {
return 'Your Site Name and Info';
}
Codex of login_message

Passing a URL variable to category.php

I need to pass a URL variable to my category.php file.
Currently my category page is at http://example.com/category-slug/
I am using the SEO plugin to rewrite http://example.com/category/category-slug and remove the /category/ part.
Also, the settings formy permalinks are set to this option in the settings menu: http://example.com/sample-post/
Now I need to be able to pass a variable in the URL like:
http://example.com/category-slug/?type=VALUE
or
http://example.com/category-slug/VALUE
where "type" is the name of the variable and VALUE is its value
I have tried using this piece of code in my functions.php file:
<?php
add_filter('query_vars', 'parameter_queryvars' );
function parameter_queryvars( $qvars )
{
$qvars[] = 'type';
return $qvars;
}
global $wp_query;
if (isset($wp_query->query_vars['type']))
{
print $wp_query->query_vars['type'];
}
?>
However, when I try to open http://example.com/category-slug/?type=something or http://example.com/category-slug/something I get "nothing found" and "Page not found" pages.
While I see this has been discussed over and over, none of the solutions seem to work for my case.
How do I properly pass a variable to a category page?
First of all, you code will never reach the if statement, as you return from the function before.
I also don't know which SEO tool you are using, but there is one function that goes with the "query_vars" filter: add_rewrite_rule()
I would recommend to write a little plugin which does the rewriting of the category permalink. Something like this (untested, but similar to a plugin I use):
// Flush added rewrite rules on activation
function category_permalink_rewrite_activate() {
category_permalink_rewrite_set_rewrite_rules();
flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'category_permalink_rewrite_activate' );
// Remove rewrite rule for event archives
function category_permalink_rewrite_deactivate() {
flush_rewrite_rules();
}
register_deactivation_hook( __FILE__, 'category_permalink_rewrite_deactivate' );
// Add rewrite rule for category permalink on init
add_rewrite_rule( '^category-(.*)/(.*)', 'index.php?category_name=$matches[1]&type=$matches[2]', 'top' );
kaufunction category_permalink_rewrite_set_rewrite_rules() {
}
add_filter( 'init', 'category_permalink_rewrite_set_rewrite_rules' );
// Register the custom query var so WP recognizes it
function category_permalink_rewrite_add_query_vars( $vars ) {
$vars[] = 'type';
return $vars;
}
add_filter( 'query_vars', 'category_permalink_rewrite_add_query_vars' );

Categories