Change 'home' link in breadcrumb to specific page - wordpress

I'm using the Avada theme, and trying to edit the breadcrumb Home link. It has to refer to another link. The wordpress given code isn't working. Someone got any idea?
Using original given wordpress code isn't working. The exact URL isn't doing the job, nor is the return get_permalink( $shop_page_id ).
Code below isn't working:
add_filter( 'woocommerce_breadcrumb_home_url', 'woo_custom_breadrumb_home_url' );
function woo_custom_breadrumb_home_url() {
$shop_page_id = get_option( 'woocommerce_shop_page_id' );
return get_permalink( $shop_page_id ) ;
}
Hope anyone can help me to get this done using the Avada theme?

Related

How to remove the original link of a post in Wordpress after using post_link and add_rewrite_rule to change the link?

I changed the permalinks of my posts using post_link, adding "/test/" to it.
So for example www.website.com/this-is-fun/ is now having the permalink www.website.com/test/this-is-fun/
This permalink is correctly showing in the admin, when editing a post, and also on the website the link to the post is the new one.
However, when I open this link it is not working, I get a 404. I was able to fix that with a add_rewrite_rule, but now my problem is that BOTH urls exist. I want only the new one to exist.
Am I making a mistake in the post_link part, is there a way you can automatically disable the original link and make the new one work? Or should I use add_rewrite_rule to disable the original? Or is there another way?
This is my code:
add_filter( 'post_link', 'custom_permalink', 10, 3 );
function custom_permalink( $permalink, $post, $leavename ) {
$permalink = home_url('/test/' . $post->post_name .'/' );
return $permalink;
}
add_action( 'init', 'custom_rewrite_rules' );
function custom_rewrite_rules() {
add_rewrite_rule(
'test/([^/]+)(?:/([0-9]+))?/?$',
'index.php?name=$matches[1]',
'top'
);
}
add_action( 'init','flush_rewrite_rules' );
I know I can change the permalink in the settings btw, but this new permalink will not be for all posts, so I need to do it this way.

woocommerce : Unable to override single-product template

I am trying to override woo commerce single product template but it won't get overridden.
I have done the following steps:
Added file inside my theme directory.
Added support for Woo-commerce in my functions.php file
add_action( 'after_setup_theme', 'wpse319485_add_woocommerce_support' );
function wpse319485_add_woocommerce_support() {
add_theme_support( 'woocommerce' );
}
Made sure the debug mode is off in config file
define( 'WC_TEMPLATE_DEBUG_MODE', false );
Checked the status of templates over-riden
Added an h1 tag with test text in it.
I even tried deleting everything but the default template is loaded.
What am I missing ?
I'm not sure if you are still facing this problem. I ran into the very same. After a very frustrating day, tempted to hack the plugin files, I ended up adding woocommerce.php to my theme, containing:
if ( is_product() ) {
wc_get_template( 'woocommerce/single-product.php' );
}else{
//For ANY product archive.
//Product taxonomy, product search or /shop landing
wc_get_template( 'woocommerce/archive-product.php' );
}
This is an adaptation of what I found here:
https://wordpress.org/support/topic/archive-productphp-template-overwrite-not-working/
It did not work without adding
woocommerce/

How to Stop Accessing WordPress Page When User Login

I am trying to stop users from accessing a page when they already login. Anyone please help me how to do this. I checked it on google and all over the stake overflow but did not find any solution. Hope to get answer soon.
Thanks
try this code bellow , put it within your theme function.
function my_page_template_redirect()
{
if( is_page( 'page-slug' ) && is_user_logged_in() )
{
wp_redirect( home_url() );
exit();
}
}
add_action( 'template_redirect', 'my_page_template_redirect' );
Change page slug based on your case, you also can use page_id check these references bellow. Don't forget to save permalink after put that code
Reference :
https://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect
https://developer.wordpress.org/reference/functions/is_page/

Adding author info outside the loop in Genesis

I'm posting this question as I'm having a little trouble adding the author info to my post hero on my website.
I'm using the Genesis framework with Wordpress, so what I did is removing the post info from the post and adding it back in the post hero. That all works, except that the author name is not being shown anymore as it's not yet fetched in the post loop.
// Remove entry title
remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
// Remove post info
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
// Add page title
add_action( 'hero-info', 'genesis_do_post_title' );
// Add page info
add_action( 'hero-info', 'genesis_post_info', 12 );
To be able to add the post author info back in the post hero, I've looked up stackoverflow and found a link where the OP was able to fix it by creating a shortcode for it and running it in the hero-info
function author_shortcode() {
global $post;
$author_id=$post->post_author;
the_author_meta( 'display_name', $author_id );
}
add_shortcode('author', 'author_shortcode');
This shortcode [author] is then added into
add_filter( 'genesis_post_info', 'custom_post_info' );
function custom_post_info( $post_info ) {
if ( is_archive() || is_home() ) {
$post_info = __( 'Article by [author] [post_author_posts_link] on [post_date] - [post_comments zero="Leave a Comment" one="1 Comment" more="% Comments" hide_if_off="disabled"]', 'tcguy' );
return $post_info;
}
}
This is the result now: http://imgur.com/a/6lX5J
It is shown in the wrong place for some reason. Anybody knows how this can be?
The site can be found here: http://websforlocals.com/business/
Hope I gave enough info, and that someone with the same problem can be helped out.
It is issue in your ShortCode registering php code.
When adding short-code we should not ECHO anything as this way it will not be echoed at the place we want to but at the top of the post content.
So always return the output in short code function, and then echo the short-code function.
Now WordPress have a convention for functions which echo the result and which returns the result, i.e. the_author_meta vs get_the_author_meta (first one which you are using will display/echo the result, however get_ functions will return the values).
We need to use get_the_author_meta instead of the_author_meta in your shortcode registering block and it will solve your displaying location issue.
function author_shortcode() {
global $post;
$author_id=$post->post_author;
return get_the_author_meta( 'display_name', $author_id );
}
add_shortcode('author', 'author_shortcode');

Hook taxonomy template to category template

I've created a plugin which registers a custom post type and a custom taxonomy for me.
Now, whenever I visit: www.mysite.com/events_categories/category I should get a list of all the posts under that category. I want to use my own template and not Wordpress' default category template. Also, I want this template to be used for ALL categories, not just one category.
I used this code:
function taxonomy_template() {
global $post;
if( is_tax( 'event_categories' ) ) {
$tax_tpl = dirname( __FILE__ ) . '\taxonomy-event_categories.php';
}
return $tax_tpl;
}
add_filter( 'template_include', 'taxonomy_template' );
And while it works for the taxonomy, it makes everything else on the site go blank. This is because the $tax_tpl is empty if the page I'm on isn't a taxonomy.
I've tried using template_redirect, but no luck either.
So I want to know how to hook my template (taxonomy-event_categories.php) to the Wordpress' category template.
Hope you guys have a solution, because I've looked everywhere and it's possible to find the solution, yet I see many plugins doing this effortlessly.
Okay, so I solved it using this code:
add_action('template_redirect', 'taxonomy_template');
function taxonomy_template( ){
$tax_tpl = dirname( __FILE__ ) . '\taxonomy-event_categories.php';
if( is_tax('event_categories') ) {
include $tax_tpl;
die();
}
}
I've no idea why this works because I think I already tried this specific code, but it didn't work. Let's just hope it will keep working.

Resources