Skip to content

Instantly share code, notes, and snippets.

View nfsarmento's full-sized avatar

NS nfsarmento

View GitHub Profile
@nfsarmento
nfsarmento / functions.php
Last active October 30, 2018 14:43
Stopping Cart Fragments From Updating in WooCommerce
/** Stopping Cart Fragments From Updating in WooCommerce
*
* https://www.nuno-sarmento.com
*/
add_action( 'wp_print_scripts', 'ns_cart_fragments', 100 );
function ns_cart_fragments() {
wp_dequeue_script( 'wc-cart-fragments' );
return true;
}
@nfsarmento
nfsarmento / functions.php
Last active October 30, 2018 14:43
Remove Query Strings From Static Resources
/** Remove Query Strings From Static Resources
*
* https://www.nuno-sarmento.com
*/
function ns_remove_script_version( $src ){
$parts = explode( '?', $src );
return $parts[0];
}
add_filter( 'script_loader_src', 'ns_remove_script_version', 15, 1 );
@nfsarmento
nfsarmento / functions.php
Last active October 30, 2018 14:42
Detect Browser : If you want to use a different stylesheet for different browsers you can use HTML conditional tags or you can use this.
/** Detect Browser : If you want to use a different stylesheet for different browsers you can use HTML conditional tags or you can use this.
*
* https://www.nuno-sarmento.com
*/
add_filter('body_class','ns_browser_body_class');
function ns_browser_body_class($classes) {
global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
@nfsarmento
nfsarmento / functions.php
Last active October 30, 2018 14:42
WordPress: Allow Contributors to Upload Images
/** WordPress: Allow Contributors to Upload Images
*
* https://www.nuno-sarmento.com
*/
if ( current_user_can('contributor') && !current_user_can('upload_files') )
add_action('admin_init', 'ns_allow_contributor_uploads');
function ns_allow_contributor_uploads() {
$contributor = get_role('contributor');
$contributor->add_cap('upload_files');
}
@nfsarmento
nfsarmento / functions.php
Last active October 30, 2018 14:41
Remove Menus in WordPress Dashboard
/** Remove Menus in WordPress Dashboard
*
* https://www.nuno-sarmento.com
*/
function ns_remove_menus () {
global $menu;
$restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins'));
end ($menu);
@nfsarmento
nfsarmento / .htaccess
Created September 5, 2018 15:25 — forked from Zodiac1978/.htaccess
Make your Website faster - a safe htaccess way
#
# Sources:
# http://stackoverflow.com/questions/7704624/how-can-i-use-gzip-compression-for-css-and-js-files-on-my-websites
# http://codex.wordpress.org/Output_Compression
# http://www.perun.net/2009/06/06/wordpress-websites-beschleuinigen-4-ein-zwischenergebnis/#comment-61086
# http://www.smashingmagazine.com/smashing-book-1/performance-optimization-for-websites-part-2-of-2/
# http://gtmetrix.com/configure-entity-tags-etags.html
# http://de.slideshare.net/walterebert/die-htaccessrichtignutzenwchh2014
# http://de.slideshare.net/walterebert/mehr-performance-fr-wordpress
#
@nfsarmento
nfsarmento / single.php
Created September 13, 2018 16:15
Next and previous post with post thumbnails
<?php $prevPost = get_previous_post();
$prevthumbnail = get_the_post_thumbnail($prevPost->ID,array(80,97)); ?>
<h2><?php previous_post_link('%link', 'Previous'); ?></h2>
<?php previous_post_link('%link', $prevthumbnail); ?>
<?php // Display the thumbnail of the next post ?>
<?php $nextPost = get_next_post();
$nextthumbnail = get_the_post_thumbnail($nextPost->ID,array(80,97)); ?>
@nfsarmento
nfsarmento / functions.php
Last active October 30, 2018 14:40
WordPress breadcrumbs
/**
* Generate breadcrumbs
*
* https://www.nuno-sarmento.com
*/
function get_breadcrumb() {
echo '<a href="'.home_url().'" rel="nofollow">Home</a>';
if (is_category() || is_single()) {
echo "&nbsp;&nbsp;&#187;&nbsp;&nbsp;";
@nfsarmento
nfsarmento / functions.php
Created September 25, 2018 11:33
Get category title with url
<h5 class="category-title">
<?php
$terms = get_the_terms( $post->ID , 'sector' );
foreach ( $terms as $term ) {
echo '&nbsp;<a href="' .esc_url( home_url( '/' ) ). $term->slug . '" title="' . $term->name . '" ' . '>' . $term->name .'</a> &nbsp;';
}
?>
</h5>
@nfsarmento
nfsarmento / functions.php
Last active October 30, 2018 14:40
Add WooCommerce Cart Icon With Cart Count To Your Theme’s Header
/**
* Ensure cart contents update when products are added to the cart via AJAX
*
* https://www.nuno-sarmento.com
*/
function my_header_add_to_cart_fragment( $fragments ) {
ob_start();
$count = WC()->cart->cart_contents_count;