I have problem with WooCommerce sidebar on archive-page and categories page,
Its display under my products ( right after page-pagi )
I tried to style it with css, like
.woocommerce .products ul, .woocommerce ul.products { width: 70%; float: right )
.sidebar { width: 29%; float: left;}
But it looks like it's in completely another section or something cause this have no effect.
If your theme isn't configured to work with woocommerce, and you've just installed it, it will probably be totally messed up. What you can do is add your own containers. Put these in functions.php
if (!function_exists('custom_open_woocommerce_content_wrappers')) {
function custom_open_woocommerce_content_wrappers(){
echo '<div class="container shop_container"><div class="row">';
}
}
if (!function_exists('custom_close_woocommerce_content_wrappers')) {
function custom_close_woocommerce_content_wrappers(){
echo '</div></div>';
}
}
if (!function_exists('custom_product_wrapper_open')) {
function custom_product_wrapper_open(){
echo '<div class="span8 content_with_right_sidebar">';
}
}
if (!function_exists('custom_product_wrapper_close')) {
function custom_product_wrapper_close(){
echo '</div>';
}
}
if (!function_exists('custom_before_shop_loop_sidebar')) {
function custom_before_shop_loop_sidebar() {
echo '<aside class="span4 sidebar sidebar_right">';
dynamic_sidebar('Sidebar Name Goes Here');
echo '</aside>';
}
}
add_action( 'woocommerce_after_shop_loop', 'custom_before_shop_loop_sidebar', 20);
if (!function_exists('custom_prepare_woocommerce_wrappers')) {
function custom_prepare_woocommerce_wrappers(){
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_output_content_wrapper', 10);
remove_action( 'woocommerce_after_shop_loop', 'woocommerce_output_content_wrapper_end', 10);
add_action( 'woocommerce_before_main_content', 'custom_open_woocommerce_content_wrappers', 10 );
add_action( 'woocommerce_after_main_content', 'custom_close_woocommerce_content_wrappers', 10 );
add_action( 'woocommerce_before_shop_loop', 'custom_product_wrapper_open', 10 );
add_action( 'woocommerce_after_shop_loop', 'custom_product_wrapper_close', 10 );
}
}
add_action( 'wp_head', 'custom_prepare_woocommerce_wrappers' );
This will create a wrapper with a right sidebar. And you can style it with
.container{
width: 1170px;
margin: 0 auto;
}
.row{
width: 100%;
}
.row:before,
.row:after{
display: table;
line-height: 0;
content: "";
}
.row:after{
clear: both;
}
.row > [class*="span"]{
display: block;
float: left;
width: 100%;
min-height: 20px;
margin-left: 2.564102564102564%;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.row > [class*="span"]:first-child{
margin-left: 0;
}
.row .span8 {width: 65.81196581196581%;}
.row .span4 {width: 31.62393162393162%;}
Etc.
You can customize the wrappers to your liking, add options to choose left/right no sidebar by linking it with customizer, etc.
Basically, you can add your own classes in those divs, that will suit your needs. This one has these classes because when I'm working with themes I use grid that has 12 columns, and it has container with 1170px width and row and spans (1-12 corresponding to columns).
Hope this helps :)
set .woocommerce and .sidebar padding and margin = 0
Related
Good Day,
I want to have a custom CSS for certain woo-commerce product category pages, to exclude the sidebar and make the content full width of the page. now I can get the CSS to work on these pages but I have over 450 categories. is there a way to make the term-id dynamic for excluded categories
the script I have so far is as follows
if ( !is_product_category( array( 'cat1','cat3','cat4','cat6') ) ) {
add_action( 'wp_head', function () { ?>
<style>
/*Hide SideBar*/
#primary {
width: 100%!important;
border-right: 0px!important;
}
.term-1 .ast-right-sidebar #secondary,.term-3 .ast-right-sidebar #secondary,.term-4 .ast-right-sidebar #secondary,.term-6 .ast-right-sidebar #secondary{
border-left: 0px!important
}
.term-1.sidebar-main,.term-3 .sidebar-main,.term-4 .sidebar-main,.term-6 .sidebar-main {
display:none!important
}
.term-1 #secondary,.term-3 #secondary,.term-4 #secondary,.term-6 #secondary {
display: none!important;
border-right: 0px solid #eee!important;
}
.term-1 .widget-area .secondary,.term-3 .widget-area .secondary,.term-4 .widget-area .secondary,.term-6 .widget-area .secondary
{
display: none!important;
}
.term-1 .ast-right-sidebar #primary,.term-3 .ast-right-sidebar #primary,.term-4 .ast-right-sidebar #primary,.term-6 .ast-right-sidebar #primary {
border-right: 0px solid #eee!important;
}
</style>
<?php } );
}
I would like to dynamically add the term-id to the CSS so that the CSS is more compact and does not get too long. any suggestions, please
#CBroe thanks for pointing me in the right direction.
The first thing I did is make a code snippet that you can copy and paste into the functions.php page of your child's theme or use plugins like code snippet. so when your theme updates you do not lose any of your code.
the first part that I did was as follows, I added this CSS to the body of the page.
add_filter('body_class', 'add_custom_body_class');
function add_custom_body_class($classes){
if(is_product_category(array( 'cat1','cat3','cat4','cat6'))){
$classes[] = 'your_new_class_here';
}
return $classes;
}
then I create a new snippet where I will add the class into the header now keep in mind that you do not want to have this code on every page so we will also add the is_product_category to the snippet to show code only when we are on that page
if ( !is_product_category( array( 'cat1','cat3','cat4','cat6') ) ) {
add_action( 'wp_head', function () { ?>
<style>
/*Hide SideBar*/
body.your_new_class_here .ast-right-sidebar #secondary { border-left: 0px!important; }
body.your_new_class_here .sidebar-main { display:none!important; }
#primary {
width: 100%!important;
border-right: 0px!important;
}
#secondary {
display: none!important;
border-right: 0px solid #eee!important;
}
</style>
<?php } );
}
What this does is add the CSS classes to the pages that you specified, hope this helped someone else
I want to remove the thumbnails from the gallery (flexslider) of the product single page.
But I want to keep the arrow for the previous/next images (in case there is more than 1 image).
I found the following code:
add_action( 'woocommerce_product_thumbnails', 'enable_gallery_for_multiple_thumbnails_only', 5 );
function enable_gallery_for_multiple_thumbnails_only() {
global $product;
if( ! is_a($product, 'WC_Product') ) {
$product = wc_get_product( get_the_id() );
}
if( empty( $product->get_gallery_image_ids() ) ) {
remove_action( 'woocommerce_product_thumbnails', 'woocommerce_show_product_thumbnails', 20 );
}
}
Source: https://stackoverflow.com/a/56238267/1788961
The problem is, that the function removes the thumbnail and the arrows.
Is there any way to keep the arrows?
And I know, that I could use display:none or maybe change the template file.
But I'm searching a solution with an own function.
if you want keep only arrow then you just put this code in functions.php:
// for arrow on single product page slide
add_filter( 'woocommerce_single_product_carousel_options', 'sf_update_woo_flexslider_options' );
/**
* Filer WooCommerce Flexslider options - Add Navigation Arrows
*/
function sf_update_woo_flexslider_options( $options ) {
$options['directionNav'] = true;
return $options;
}
And this code put it in your theme style.css file:
/*add for arrow on main image slide*/
ul.flex-direction-nav {
position: absolute;
top: 30%;
z-index: 99999;
width: 100%;
left: 0;
margin: 0;
padding: 0px;
list-style: none;
}
li.flex-nav-prev {float: left;}
li.flex-nav-next {float: right;}
a.flex-next {visibility:hidden;}
a.flex-prev {visibility:hidden;}
a.flex-next::after {
visibility:visible;content: '\f054';
font-family: 'Font Awesome 5 Free';
margin-right: 10px;
font-size: 20px;
font-weight: bold;
}
a.flex-prev::before {
visibility:visible;
content: '\f053';
font-family: 'Font Awesome 5 Free';
margin-left: 10px;
font-size: 20px;
font-weight: bold;
}
ul.flex-direction-nav li a {
color: black;
}
ul.flex-direction-nav li a:hover {
text-decoration: none;
}
.flex-control-nav .flex-control-thumbs{
display: none;
}
add_filter( 'woocommerce_single_product_carousel_options', 'sf_update_woo_flexslider_options' );
/**
* Filer WooCommerce Flexslider options - Add Navigation Arrows
*/
function sf_update_woo_flexslider_options( $options ) {
$options['directionNav'] = true;
$options['controlNav'] = false;
return $options;
}
The given approved answer is close but still resorts to CSS to hide the thumbnails.
You can disable controlNav directly on the same filter you use to show the arrows.
My WordPress theme ("Function") uses an ugly "progress bar" style ratings system which overrides the default WooCommerce star-ratings. See below:
http://demo.woothemes.com/function/shop/castillo-cap/#tab-reviews
For the life of me I can't figure out how remove this and replace it with the default/original WooCommerce star-ratings, the ones that actually look like stars (font awesome I believe?)
I believe what needs to be done is to somehow overwrite or prioritize WooCommerce star-ratings css over the theme's. Ultimately I would like for all of the progress bars (shop page & individual product pages, review submission forms) to be replaced with the default WordPress stars, however at the moment I can settle for just the shop page where the ratings (progress bars) appear under the product's photos
I was able to find the css code controlling (creating?) the progress bars in Function->Includes->Integrations->woocommerce->css->woocommerce.css However, I also found some suspicious looking code in woocommerce.less located in the same css folder.
Here is code I found in woocommerce.css:
star-rating {
width: 80px;
height: 1em;
background: #eaeaea;
-webkit-border-radius: 3.631em;
border-radius: 3.631em;
-moz-background-clip: padding;
-webkit-background-clip: padding-box;
background-clip: padding-box;
clear: both;
}
.star-rating span {
background: #52a0cd;
height: 100%;
overflow: hidden;
float: left;
text-indent: -999em;
-webkit-box-sizing: border-box;
/* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box;
/* Firefox, other Gecko */
box-sizing: border-box;
/* Opera/IE 8+ */
-webkit-border-radius: 3.631em;
border-radius: 3.631em;
-moz-background-clip: padding;
-webkit-background-clip: padding-box;
background-clip: padding-box;
}
.star-rating span span {
display: none;
}
p.stars {
overflow: hidden;
zoom: 1;
}
p.stars span {
width: 80px;
height: 16px;
position: relative;
float: left;
background: #eaeaea;
-webkit-border-radius: 3.631em;
border-radius: 3.631em;
-moz-background-clip: padding;
-webkit-background-clip: padding-box;
background-clip: padding-box;
}
p.stars span a {
float: left;
position: absolute;
left: 0;
top: 0;
width: 16px;
height: 0;
padding-top: 16px;
overflow: hidden;
}
p.stars span a:hover,
p.stars span a:focus {
background: #52a0cd;
-webkit-border-radius: 3.631em;
border-radius: 3.631em;
-moz-background-clip: padding;
-webkit-background-clip: padding-box;
background-clip: padding-box;
}
p.stars span a.active {
background: #52a0cd;
-webkit-border-radius: 3.631em;
border-radius: 3.631em;
-moz-background-clip: padding;
-webkit-background-clip: padding-box;
background-clip: padding-box;
}
p.stars span a.star-1 {
width: 16px;
z-index: 10;
-webkit-border-top-left-radius: 3.631em;
-webkit-border-bottom-left-radius: 3.631em;
border-top-left-radius: 3.631em;
border-bottom-left-radius: 3.631em;
-moz-background-clip: padding;
-webkit-background-clip: padding-box;
background-clip: padding-box;
}
p.stars span a.star-2 {
width: 32px;
z-index: 9;
}
p.stars span a.star-3 {
width: 48px;
z-index: 8;
}
p.stars span a.star-4 {
width: 64px;
z-index: 7;
}
p.stars span a.star-5 {
width: 80px;
z-index: 6;
}
...and here is what I found in woocommerce.less:
// Single product
.single-product {
.summary {
.woocommerce-product-rating {
.clearfix;
.star-rating {
float: left;
margin: .327em 0 0;
}
.woocommerce-review-link {
float: right;
display: block;
}
}
// General WooCommerce
.star-rating {
width:80px;
height: 1em;
background: #border_main;
.border_radius(3.631em);
clear:both;
span {
background: #color_links;
height:100%;
overflow: hidden;
float: left;
text-indent: -999em;
.borderbox;
.border_radius(3.631em);
span {
display: none;
}
}
}
p.stars {
overflow: hidden;
zoom: 1;
span {
width: 80px;
height: 16px;
position: relative;
float: left;
background: #border_main;
.border_radius(3.631em);
a {
float: left;
position: absolute;
left: 0;
top: 0;
width: 16px;
height: 0;
padding-top: 16px;
overflow: hidden;
}
a:hover, a:focus {
background: #color_links;
.border_radius(3.631em);
}
a.active {
background: #color_links;
.border_radius(3.631em);
}
a.star-1 { width: 16px; z-index: 10; .border_radius_left(3.631em); }
a.star-2 { width: 32px; z-index: 9; }
a.star-3 { width: 48px; z-index: 8; }
a.star-4 { width: 64px; z-index: 7; }
a.star-5 { width: 80px; z-index: 6; }
}
}
...along with some more for the widget areas, reviews, etc. etc.
I've found a few posts on how to override default WooCommerce star-ratings with a Theme's, but I can't find anything on doing the reverse. I did come across this:
http://findnerd.com/list/view/How-to-show-stars-instead-of-theme-ratings-in-Woocommerce/3854/
However it didn't work for me...
Any help would be much MUCH appreciated. Thank you!
EDIT:
I was informed this might be caused by my functions.php file. Here is the code found in wp-content->themes->Function-Child->functions.php
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
/*-----------------------------------------------------------------------------------*/
/* Start WooThemes Functions - Please refrain from editing this section */
/*-----------------------------------------------------------------------------------*/
// WooFramework init
require_once ( get_template_directory() . '/functions/admin-init.php' );
/*-----------------------------------------------------------------------------------*/
/* Load the theme-specific files, with support for overriding via a child theme.
/*-----------------------------------------------------------------------------------*/
$includes = array(
'includes/theme-options.php', // Options panel settings and custom settings
'includes/theme-functions.php', // Custom theme functions
'includes/theme-actions.php', // Theme actions & user defined hooks
'includes/theme-comments.php', // Custom comments/pingback loop
'includes/theme-js.php', // Load JavaScript via wp_enqueue_script
'includes/sidebar-init.php', // Initialize widgetized areas
'includes/theme-widgets.php', // Theme widgets
'includes/theme-plugin-integrations.php' // Plugin integrations
);
// Allow child themes/plugins to add widgets to be loaded.
$includes = apply_filters( 'woo_includes', $includes );
foreach ( $includes as $i ) {
locate_template( $i, true );
}
/*-----------------------------------------------------------------------------------*/
/* You can add custom functions below */
/*-----------------------------------------------------------------------------------*/
This is the exact same as the code in my regular (non-child) theme's functions.php file. I do have some custom code below this, however none of it relates to anything that would be relevant here.
EDIT 2:
OK I think I'm getting closer here!! I found this file wp-content/themes/function/includes/integrations/woocommerce/woocommerce.php which included this code at the top:
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
global $woo_options;
add_theme_support( 'woocommerce' );
// Disable WooCommerce styles
if ( version_compare( WOOCOMMERCE_VERSION, '2.1' ) >= 0 ) {
// WooCommerce 2.1 or above is active
add_filter( 'woocommerce_enqueue_styles', '__return_false' );
} else {
// WooCommerce less than 2.1 is active
define( 'WOOCOMMERCE_USE_CSS', false );
}
// Load WooCommerce stylsheet
if ( ! is_admin() ) { add_action( 'wp_enqueue_scripts', 'woo_load_woocommerce_css', 20 ); }
if ( ! function_exists( 'woo_load_woocommerce_css' ) ) {
function woo_load_woocommerce_css () {
wp_register_style( 'woocommerce', esc_url( get_template_directory_uri() . '/includes/integrations/woocommerce/css/woocommerce.css' ) );
wp_enqueue_style( 'woocommerce' );
} // End woo_load_woocommerce_css()
}
When I deleted the above code, the progress bars changed a little, and in the add new review section I could actually see two blue STARS laid on top of the blank progress bar (which normally highlights blue when you scroll over to choose your rating). So it seems that removing this kinda half fixed the problem. Any further suggestions?
I'm building a stock photo site and it is (I think) good to show only pictures on the shops home page.
I figured out how to hide the Titles, Prices and Buttons (with remove_action) in my twentytwelve child theme (functions.php)
Now on adding masonry. I added a bit of code (a snippet from James Koster) to enqueue the WP build in Masonry script.
add_action( 'wp_enqueue_scripts', 'jk_masonry' );
function jk_masonry() {
wp_enqueue_script( 'jquery-masonry', array( 'jquery' ) );
}
I added the following code to my footer.php and I can see in the markup that it is loaded.
<script>
jQuery(document).ready(function($) {
$('#content').masonry({
itemSelector: 'products',
isAnimated: true;
});
});
</script>
No changes on my page.
I added this to my child theme styl.css:
.woocommerce ul.products li.product,
.woocommerce-page ul.products li.product,
#primary ul.products li.product{
margin-right: 3px;
margin-bottom: 3px;
}
Sadly, no effect on my page. No Masonry effects, no changes in the margins of the items. See screenshot.
The question is: were to go from here. I've searched the internet, found several possibilities but it seems to be that I don't understand it. (newbie) I'm looking for a result as shown here: lhotse masonry.
EDIT: html output
<div id="primary" class="site-content"><div id="content" role="main">
<div class="page-description"><div class="post-text"></div>
<p> </p>
</div>
<ul class="products">
<li class="post-70 product type-product status-publish has-post-thumbnail first sale taxable shipping-taxable purchasable product-type-simple product-cat-posters product-tag-adri instock">
<a href="http://localhost/shop/flying-ninja/">
<img width="600" height="600" src="http://localhost/wp-content/uploads/2013/06/poster_2_up-600x600.jpg" class="attachment-shop_catalog wp-post-image" alt="poster_2_up" />
</a>
</li>
<!-- Following items-->
</ul>
END EDIT
EDIT NR. 2
Yesterday I learned a method to override the standard woocommerce css files. If curious... throw me a line. However in the case of my problem it is only a bit of the solution. As formerly stated I want to use masonry on my woocommerce shoppage. The way it works looks like this:
As you can see there are 4 columns to fill the total widht of the surrounding div. However Masonry did not kicked in. When I resize my browser window to a smaller size the images are not resizing. (responsive) till a certain screen width. Then suddenly the layout changes to a 3 column layout and masonry kickes in. See screenshot.
The change to 3-columns must have something to do with css.... however I can't figure out what. Silly me.
Then when resizing the screen further (smaller) The layout went to two columns (that's understandable) but masonry stops working. See screenshot.
I did expect a working masonry and responsive layout.
END EDIT 2
Im totally stucked here.
Any help is very, very much appreciated. Thanks in advance.
At first I needed to override the standard woocommerce css behavior. As mevius suggested in the comments above this was a possibility. So I dequeued the styles, copied the files into my /childtheme/woocommerce/css folder en enqueued them on this new location. This way when an update is coming out the css files are not overwritten. Here is the code for the functions.php of my child theme:
add_filter( 'woocommerce_enqueue_styles', 'jk_dequeue_styles' );
function jk_dequeue_styles( $enqueue_styles ) {
unset( $enqueue_styles['woocommerce-general'] ); // Remove the gloss
unset( $enqueue_styles['woocommerce-layout'] ); // Remove the layout
unset( $enqueue_styles['woocommerce-smallscreen'] ); // Remove the smallscreen optimisation
return $enqueue_styles;
}
function wp_enqueue_woocommerce_style(){
wp_register_style( 'woocommerce-layout', get_stylesheet_directory_uri() . '/woocommerce/css/woocommerce-layout.css' );
if ( class_exists( 'woocommerce' ) ) {
wp_enqueue_style( 'woocommerce-layout' );
}
wp_register_style( 'woocommerce-smallscreen', get_stylesheet_directory_uri() . '/woocommerce/css/woocommerce-smallscreen.css' ,array(),'4.0.1','only screen and (max-width: 768px)' );
if ( class_exists( 'woocommerce' ) ) {
wp_enqueue_style( 'woocommerce-smallscreen' );
}
wp_register_style( 'woocommerce-general', get_stylesheet_directory_uri() . '/woocommerce/css/woocommerce.css' );
if ( class_exists( 'woocommerce' ) ) {
wp_enqueue_style( 'woocommerce-general' );
}
}
To get masonry working I added the following to my functions.php just above the dequeueing and enqueuing of the woocommerce style sheets.
add_action( 'wp_enqueue_scripts', 'jk_masonry' );
function jk_masonry() {
wp_enqueue_script( 'jquery-masonry', array( 'jquery' ) );
}
and I put this code in my child themes footer.php:
<script>
jQuery(document).ready(function($) {
$('.products').masonry({
itemSelector: '.product',
isAnimated: true
});
});
</script>
Next I had to change some styles in the woocommerce css files.
I changed the rules below to: (just perform a search in your css files)
In woocommerce.css:
.woocommerce .products ul li,
.woocommerce ul.products li,
.woocommerce-page .products ul li,
.woocommerce-page ul.products li {
list-style: none;
width: 24.3%;
margin-right: 8px;
margin-bottom: 8px;
}
.woocommerce ul.products li.product a img,
.woocommerce-page ul.products li.product a img {
width: 100%;
height: auto;
display: block;
-webkit-transition: all ease-in-out .2s;
-moz-transition: all ease-in-out .2s;
-o-transition: all ease-in-out .2s;
transition: all ease-in-out .2s;
}
Some of the above ar just cosmetic.
In the woocommerce-layout.css file:
.woocommerce ul.products li.product,
.woocommerce-page ul.products li.product {
float: left;
margin: 0 8px 8px 0;
padding: 0;
position: relative;
width: 24.5%;
}
and in the woocommerce-smallscreen.css :
.woocommerce ul.products li.product,
.woocommerce-page ul.products li.product {
width: 48%;
float: left;
clear: both;
margin: 0 2px 2px 0;
}
#media screen and (max-width: 450px) {
.woocommerce ul.products li.product,
.woocommerce-page ul.products li.product {
width: 100%;
float: left;
clear: both;
margin: 0 0 2px 0;
}
}
As far as I can tell works this quite good. Responsivness is ok. Even the images are animating to their new positions when resizing the screen. Good luck with it.
I've managed to replace the Wordpress icon/logo in the admin bar with a custom one in my functions.php file as well as removing the dropdown menu linking to Wordpress documentation, support forums, feedback etc. What i'm trying to do is to disable the link present on the logo that takes you to the About Wordpress page in the admin that explains the features of the version you currently are running.
I'd like to do this from within the functions.php file. Is this possible?
This is the code i have used so far:
// Replace Wordpress logo with custom Logo
function my_custom_logo() {
echo '
<style type="text/css">
#wp-admin-bar-wp-logo > .ab-item .ab-icon:before {
background-position: 0 0;
content: url(' . get_bloginfo('stylesheet_directory') . '/assets/img/my-logo.png)!important;
top: 2px;
display: block;
width: 15px;
height: 20px;
pointer-events: none!important;
cursor: default;
}
#wp-admin-bar-wp-logo.hover > .ab-item .ab-icon {
background-position: 0 0;
}
</style>
';
}
add_action('admin_head', 'my_custom_logo');
add_action('wp_head', 'my_custom_logo');
//disable a few items on the admin bar
function remove_admin_bar_links() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('new-content'); // Remove the 'add new' button
$wp_admin_bar->remove_menu('comments'); // Remove the comments bubble
$wp_admin_bar->remove_menu('about'); // Remove the about WordPress link
$wp_admin_bar->remove_menu('wporg'); // Remove the WordPress.org link
$wp_admin_bar->remove_menu('documentation'); // Remove the WordPress documentation link
$wp_admin_bar->remove_menu('support-forums'); // Remove the support forums link
$wp_admin_bar->remove_menu('feedback'); // Remove the feedback link
}
add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );
I had this problem a while back.
The easiest solution would not be with css but with a function that removes that menu item from the admin bar.
Then just add a new menu item with your logo image.
I would do this instead of replacing the icon with your logo with css.
/*Remove WordPress menu from admin bar*/
add_action( 'admin_bar_menu', 'remove_wp_logo', 999 );
function remove_wp_logo( $wp_admin_bar ) {
$wp_admin_bar->remove_node( 'wp-logo' );
}
/*Adds Custom Logo to Admin Bar*/
add_action( 'admin_bar_menu', 'custom_admin_logo', 1 );
//priority 1 sets the location to the front/leftmost of the menu
function custom_admin_logo( $wp_admin_bar ) {
$custom_logo_id = get_theme_mod( 'custom_logo' ); //Uses theme logo
$custom_logo_url = wp_get_attachment_image_url( $custom_logo_id , 'full' );
$args = array(
'id' => 'custom_logo_admin',
'title' => ' ',
'meta' => array( 'html' => '<li id="custom-logo-admin-bar" style="width: 230px;padding: 10px;padding-left: 0px;padding-right: 25px;"><img class="overlay" src="'.$custom_logo_url.'" style="float: left;width: 100%;height: auto;"></li>' )
);
$wp_admin_bar->add_node( $args );
}
You can style your image with css either in your stylesheet or directly here in the meta array.
The $wp_admin_bar->add_node( $args ); is what actually adds the new node into the admin bar.
P.S. some of the styling here is just what I needed for my own purposes, feel free to change.
Maybe you should just overwrite the CSS for it and replace it with your own image so the functionality will stay in tact!
This is the original CSS:
#wp-admin-bar-wp-logo > .ab-item .ab-icon {
background-image: url("../wp-includes/images/admin-bar-sprite.png?d=20120830");
background-position: 0 -76px;
background-repeat: no-repeat;
height: 20px;
margin-top: 4px;
width: 20px;
}
You might want to change it in:
#wp-admin-bar-wp-logo > .ab-item span.ab-icon {
background-image: url("your-image.png");
background-repeat: no-repeat;
height: 20px;
margin-top: 4px;
width: 20px;
}
Notice the addiational span to .ab-icon to make it more specific.
For any legal questions check their licence page:
https://codex.wordpress.org/License
And the GPL licence:
https://www.gnu.org/copyleft/gpl.html