I have created a custom theme for woocommerce an copied templates folder to my theme rootwoocommerce. now I figured that all pages in woocommerce has a div container with class woocommerce. I want to change the class of it or remove that from my theme. I searched in my theme files <div class="woocommerce"> and I found nothing. !
is there any way to change or delete that?
No, you can't change or delete, which could break everything, read more here - https://github.com/woocommerce/woocommerce/issues/12191.
You can't find because the word <div class="woocommerce"> may be a parameter of a rendering function (example: <div class="<?php echo $param">) and you must find where php code is placed instead. When you get where it is placed, just add your class after parameter (example: class="<?php echo $param?> your-class") to access this element
Related
I am trying to remove some meta boxes that have been added by a theme that is installed on my Wordpress site. I am able to target an remove the wordpress ones with the code I am using but this doesnt seem to work for the ones that are being added by the theme. Is it an issue with targeting them and the code I am using isnt correct?
function remove_page_metaboxes() {
remove_meta_box('qodef-meta-box-page_general','page','normal' );
add_action('admin_init','remove_page_metaboxes', 12);
When i inspect the code I can see the meta boxes are within these two divs, the standard wordpress and ones being added by plugins are going into 'normal-sortables' and if I use the same code with the correct ID they are able to be removed. But cant target the ones within the 'advanced-sortables'.
<div id="postbox-container-2" class="postbox-container">
<div id="normal-sortables" class="meta-box-sortables ui-sortable">
<div id="advanced-sortables" class="meta-box-sortables ui-sortable">
Am I missing something very obvious or is this not the correct way to remove these?
Any help would be greatly appreciated.
Somewhere in the html of my Woocommerce shop page I have this line:
<ul class="products columns-3">`
I'd simply like to add the bootstrap class "row" to it like:
<ul class="products columns-3 row">
I inserted the bootstrap cdn in my chrome elements tool then added the "row" and I have the result I want it but I can't find in my website files where to change it.
I know the html code is generated by functions.php, I tried to look down in almost every php page on templates and woocommerce. Can someone explain me how this can be done?
To add a custom class to <ul> html tag on WooCommerce shop and archives pages:
First read "Overriding templates via a theme" official documentation, that explains you how to override woocommerce templates via a theme.
Note for "Premium Themes":
On some premium themes, they can use already some customized WooCommerce templates, so you will have to use them instead. If you are using a child theme with it, copy the related template to your child theme, respecting the same folder hierarchy.
Once understood this, the related template to edit is loop/loop-start.php.
Open/edit it and replace:
<ul class="products columns-<?php echo esc_attr( wc_get_loop_prop( 'columns' ) ); ?>">
with:
<ul class="products columns-<?php echo esc_attr( wc_get_loop_prop( 'columns' ) ); ?> row">
Saveā¦ You are done.
I want to replace the <h2 class="fusion-post-title"> tag with <h1> tag.
I've tested the regex on regex101.com and the capturing groups are there.
Is this proper way to do so? Maybe Wordpress is not triggering my add_filter()?
function replace_content($content){
$content = preg_replace('#<h2 class="fusion-post-title"(.*?)>(.*?)<\/h2>#si', '<h1 class="fusion-post-title"${1}>${2}</h1>', $content);
return $content;
}
add_filter('the_content','replace_content');
The title isn't part of the content, hence your filter doesn't work. Last time I checked a Theme Fusion theme, the function they were using for generating titles didn't apply an filters that you could hook onto, but they did suggest that there are theme options for changing the tag used. See you have a couple of options:
You can search through the theme for fusion-post-title and see what functions come up, and whether there's any filters or options that you can use. Unfortunately, as it's a premium theme I don't have a recent copy to hand to check, otherwise I'd point you in the right direction.
You can edit the theme templates directly: I'd recommend doing this to a child theme, not the theme files directly. For more information on setting up a child theme, you should refer to the codex.
Assuming you're going with option 2: once you've got your child theme set up (i.e. you've got your functions.php and styles.css), you can copy the relevant templates from the parent theme over to the child theme, and then edit them as you wish. If you take a look at Avada's single.php you'll notice something similar to:
<?php echo avada_render_post_title( $post->ID, false, '', '2' ); ?>
The last argument - 2 - is the heading level to use (i.e h2). Simply change that to 1 and you should be good to go. Or replace it entirely with your own markup:
<h1 class="post_title"><?php the_title();?></h1>
Repeat this for which ever templates are required.
I work on a website with a custom post type, described in the functions.php file of a child theme.
I created a function, still within the functions file, that describes the beahavior of a page for this custom content : basically, to achieve that, I use get_the_terms() and get_post_meta(), within a function named add_thecontent(). It's called with a filter : add_filter('the_content','add_thecontent');
It works fine : I can retrieve the name, the custom taxonomies, the several fields...etc.
I also work on another website, still with a custom post type (a different one), with a different theme. I use the same mechanism as stated above (child theme + functions file + content called within a filter) but when I want to display a preview of my custom post, the engine calls the file content-single.php of the main theme. This file calls the_category() and that leads to warnings in my page, beacuse I don't have a "regular" category for my custom post, only custom taxonomies.
I tried to put a content-single.php in my child theme in order to redefine its beahavior, but I get errors. And I think it's not a proper way to proceed.
What I want is to force WP engine to display a custom post as I defined in the functions.php. How can I achieve that ? Thanks and sorry for my english
I would recommend you to install and debug using Which Template Plugin once you install this, you can know which file is being called to parse your custom post.
Also, take a look at the worpdress hierarchy page here
If you created a custom post, the you can create an individual page for that custom post as single-$posttype.php and you would be able to control the flow of the file.
Good luck!
Solved. In the parent theme, content-single.php included the following code :
<span class="cat-name"><?php $category = get_the_category(); echo $category[0]->cat_name; ?></span>
So I created a content-single.php in my child theme, and I made a test on the type of post. If the post is not a custom post I created, display normally its category. Else, do nothing, because I handle the taxonomies myself.
<?php if($post->post_type != 'myCustomPost') {;?>
<span class="cat-name"><?php $category = get_the_category(); echo $category[0]->cat_name; ?></span>
<?php } ?>
The WordPress theme I'm using applies a home_url() link to the header logo and I'd like to change it to network_home_url()... Easy enough if I am editing the theme files but I'd like to do it via the child theme functions.php file so I can keep all my tweaks separate from the main theme (it's a multisite installation).
This is what I'm working with (albeit simplified):
<div class="logo">
<a href="<?php echo home_url(); ?>">
<img src="/image.png">
</a>
</div>
I've tried the following, which worked but resulted in a site-wide change (including WP settings, etc) which in turn broke all the permalinks:
add_filter('home_url', 'change_logo_link');
function change_logo_link($output) {
return network_home_url();
}
Is there a way I can target that specific hyperlink without editing the parent theme files? I don't think the home_url function is used anywhere else in the theme so it doesn't need to be too specific, I just want to avoid affecting the WP settings.
Thanks in advance!!!
The concept of child themes is to allow customizing of almost everything without changing the parent theme. Just copy your parent theme's template file with that logo code to your child theme's folder and replace home_url() with network_home_url(). WordPress will use that modified child template instead of parent one if you activate this child theme on your network site.