Wordpress - Remove Version Number From CSS - css

I am using a wordpress theme, and the css file uploads with version number:
style.css?ver=1.2.8
The problem is that when i change the css file, the browser keep loading the file without my changes. I can see that the changes were saved on the server, but nothing help to load the right file.
I tried:
function remove_cssjs_ver( $src ) {
if( strpos( $src, '?ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 );
But everything disappeared.
I read the other topics on the subject but nothing helped.
Thank you.

That below given code may help you.
function vc_remove_wp_ver_css_js( $src ) {
if ( strpos( $src, 'ver=' . get_bloginfo( 'version' ) ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'vc_remove_wp_ver_css_js', 9999 );
add_filter( 'script_loader_src', 'vc_remove_wp_ver_css_js', 9999 );
Taken from https://wordpress.stackexchange.com/questions/132282/removing-wordpress-version-number-from-included-files
That works for me, hope it will work for you as well.

Add this code to the functions.php of your theme.
function remove_file_version($src){
return preg_replace("/\?ver=[0-9.]+/", "", $src);
}
add_filter('style_loader_src', 'remove_file_version', 100);
add_filter('script_loader_src', 'remove_file_version', 100);

Related

URL Query on Wordpress

I am applying specific styles in Worpdress when I access a certain URL, for example:
misiito.com/?mobile
When I enter there I hide the header and footer. My code is the following:
if ( isset( $_GET['mobile'] ) ) {
wp_enqueue_style( 'adaptabilidad', plugins_url( 'css/mobile.css', __FILE__ ), array(), '1.0.0' );
}
if ( isset( $_GET['totem'] ) ) {
wp_enqueue_style( 'adaptabilidad', plugins_url( 'css/totems.css', __FILE__ ), array(), '1.0.0' );
}
My problem is that it doesn't change the links and places the /?mobile, please help me, how can I do it?
That is, I want all the buttons at the end to have /?mobile
I tried this, but it's obviously a bug:
add_filter( 'the_content', 'adaptabilidad_nattule_add_mobile_url' );
function adaptabilidad_nattule_add_mobile_url( $content ) {
$content = str_replace( 'href="', 'href="?mobile', $content );
return $content;
}
It's just a suggestion, but have you thought of creating duplicate pages (for each styles) with different URL slugs and simply using a plugin like "Simple 301 Redirects" to associate them with a "/something"?
Example:
yousite.com/page1-style2
yousite.com/page1-style27

Post Author ID in wordpress permalinks settings

I am making my custom permalinks and want to get the post author id in it I have tried many things but all in vain, Please help me on this one.
STEP 1 add this into your functions.php
Guidance here
https://wordpress.stackexchange.com/questions/112719/how-to-use-author-id-in-post-permalink
function wpse_112719_pre_post_link( $permalink, $post, $leavename ) {
if ( strpos( $permalink, '%author%' ) !== false ) {
$authordata = get_userdata( $post->post_author );
$author_id = $authordata->ID;
$permalink = str_replace( '%author%', $author_id, $permalink );
}
return $permalink;
}
add_filter( 'pre_post_link', 'wpse_112719_pre_post_link', 10, 3 );
function wpse_112730_add_rewrite_rules() {
add_rewrite_rule(
"([0-9]+)/(.*)",
'index.php?name=$matches[2]',
'top'
);
}
add_action( 'init', 'wpse_112730_add_rewrite_rules' );
STEP 2 login to admin end and set the permalinks Custom Structure some thing like this : /%postname%/%author%

How does one replace WooCommerce default placeholder image for shop categories

I've tried the following code, which im using successfully with product thumbnails but for categories haven't found a way to do it.
add_action( 'init', 'mw_replace_woocommerce_placeholders' );
function mw_replace_woocommerce_placeholders() {
add_filter('woocommerce_placeholder_img', 'custom_woocommerce_placeholder_img');
function custom_woocommerce_placeholder_img( $src ) {
$src = '<span class="thumb-placeholder"><i class="icon-camera"></i></span>';
return $src;
}
}
Any tips?
This should work
add_action( 'init', 'custom_placeholder' );
function custom_placeholder() {
if ( is_product_category() ){
add_filter('woocommerce_placeholder_img_src','custom_placeholder_img');
function custom_placeholder_img($src) {
$upload_dir = wp_upload_dir();
$uploads = untrailingslashit( $upload_dir['baseurl'] );
$src = $uploads . '/your/directory/custom_placeholder.jpg';
return $src;
}
}
}
Or you could replace the placeholder located at "wp-content/plugins/woocommerce/assets/images/placeholder.png" with your own.
The line:
if ( is_product_category() ){
in functions.php makes the theme reliant on the plugin, so if you deactivate woocommerce for testing, it breaks the site. At least that's what happened to me.

Wordpress Not Updating Stylesheet

My wordpress website is not updating the stylesheet its using instead of style.css it is showing "style.css?ver=3.8.3"
I want to know why is this happening and where does this version thingie come from since I've checked both via admin panel and the ftp and have reset cache but still its getting its styles from some other version of the styelsheet.
It would be really helpful if someone points out the logic behing this. Many Thanks!
You have to set the '$ver' parameter to 'null' in the call to style-sheet in your theme files
wp_enqueue_style( $handle, $src, $deps, $ver, $media );
Add this code to the functions.php file of your WordPress theme
function remove_cssjs_query_string( $src ) {
if( strpos( $src, '?ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'remove_cssjs_query_string', 10, 2 );
add_filter( 'script_loader_src', 'remove_cssjs_query_string', 10, 2 );
This code will remove query strings (?ver=) parameter from all the CSS and JS files on your site.
add_filter( 'style_loader_src', 'remove_cssjs_query_string', 10, 2 );
Above line removes query strings from all CSS files
add_filter( 'script_loader_src', 'remove_cssjs_query_string', 10, 2 );
Above line removes query strings from all JS files
Hope it helps :)
Source : http://belnad.com/remove-ver-query-string-wordpress-css-js-files/

WordPress: Custom default avatar on localhost?

I'm trying to add a custom default avatar to WordPress in functions.php, but the image is not displaying in Settings/Discussion or elsewhere on the site. The code works because a new radio field is added with the custom field name, but the image won't display. Is the avatar not displaying because I'm using Localhost?
I don't have enough reps to comment on similar questions.
here's the code:
add_filter( 'avatar_defaults' , 'wps_new_avatar' );
function wps_new_avatar( $avatar_defaults ){
$new_avatar = get_stylesheet_directory_uri() . '/images/default-avatar.png';
$avatar_defaults[$new_avatar] = "Default Avatar";
return $avatar_defaults;
}
I've tried other examples and the 'Add-New-Default-Avatar' plugin with the same result.
I was facing the same issue and came up with this completely hackish solution... It works though :)
add_filter( 'get_avatar', 'so_14088040_localhost_avatar', 10, 5 );
function so_14088040_localhost_avatar( $avatar, $id_or_email, $size, $default, $alt )
{
$whitelist = array( 'localhost', '127.0.0.1' );
if( !in_array( $_SERVER['SERVER_ADDR'] , $whitelist ) )
return $avatar;
$doc = new DOMDocument;
$doc->loadHTML( $avatar );
$imgs = $doc->getElementsByTagName('img');
if ( $imgs->length > 0 )
{
$url = urldecode( $imgs->item(0)->getAttribute('src') );
$url2 = explode( 'd=', $url );
$url3 = explode( '&', $url2[1] );
$avatar= "<img src='{$url3[0]}' alt='' class='avatar avatar-64 photo' height='64' width='64' />";
}
return $avatar;
}
Result:
Of course, this filter is meant for development only.

Resources