Skip to content

Instantly share code, notes, and snippets.

Nuno Morais Sarmento nfsarmento

Block or report user

Report or block nfsarmento

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nfsarmento
nfsarmento / apachevhost.sh
Last active Nov 14, 2019
Create apache2 virtual hosts on Ubuntu.
View apachevhost.sh
#! /bin/bash
# This script is used for creating apache2 virtual hosts on Ubuntu.
# Created by Nuno Sarmento from http://www.nuno-sarmento.com.
#
# DN = domainname -- used in apache config file
# DocRt is /var/www-vhosts/$DN
# Logs go in /var/log/apache2/$DN
#
echo -n "Enter full domain name without wwww (e.g. example.com): "
read -e DN
@nfsarmento
nfsarmento / functions.php
Last active Nov 4, 2019
Add a custom image to WordPress User Profile
View functions.php
/**
*
* Add custom user profile information
*
*/
add_action( 'show_user_profile', 'ns_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'ns_show_extra_profile_fields' );
function ns_show_extra_profile_fields( $user ) { ?>
<h3>Extra profile information</h3>
@nfsarmento
nfsarmento / functions.php
Created Oct 1, 2019
Allow SVG on wordpress without plugin
View functions.php
// Allow SVG without plugin
add_filter( 'wp_check_filetype_and_ext', function($data, $file, $filename, $mimes) {
global $wp_version;
if ( $wp_version !== '4.7.1' ) {
return $data;
}
$filetype = wp_check_filetype( $filename, $mimes );
@nfsarmento
nfsarmento / functions.php
Created Sep 20, 2019
Gravity Forms - product field "user defined" price max value
View functions.php
// Form product field validation - max price of £500
// gform_field_validation_3_9 the 3 is your form ID and the 9 is your field ID
add_filter( 'gform_field_validation_3_9', 'price_custom_validation', 10, 4 );
function price_custom_validation( $result, $value, $form, $field ) {
//change value for price field to just be numeric (strips off currency symbol, etc.) using Gravity Forms to_number function
//the second parameter to to_number is the currency code, ie "USD", if not specified USD is used
$number = GFCommon::to_number( $value, '' );
if ( $result['is_valid'] && intval( $number ) > 500 ) {
$result['is_valid'] = false;
@nfsarmento
nfsarmento / ns_social_sharing_buttons.php
Last active Sep 19, 2019
Social sharing shortcode buttons
View ns_social_sharing_buttons.php
function ns_social_sharing_buttons($content) {
// Get current page URL
$nsURL = urlencode(get_permalink());
// Get current page title
$nsTitle = htmlspecialchars(urlencode(html_entity_decode(get_the_title(), ENT_COMPAT, 'UTF-8')), ENT_COMPAT, 'UTF-8');
// Get Post Thumbnail for pinterest
$nsThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
@nfsarmento
nfsarmento / get-isotope-items.php
Created Aug 6, 2019 — forked from mohandere/get-isotope-items.php
jQuery isotope plugin for wordpress posts filtering by category with pagination.
View get-isotope-items.php
<?php
function get_isotope_item( $query_args = array() ){
$defaults = array(
'post_type' => 'post',
'posts_per_page' => -1,
'post_status' => 'publish',
);
View smooth-jump.js
jQuery(function( $ ){
// Jump to home-arrow id
// or remove ID to select all links with hashes
$('a[href*="#home-jump"]')
.click(function(event) {
// On-page links
if (
location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') &&
location.hostname == this.hostname
@nfsarmento
nfsarmento / functions.php
Created Jun 7, 2019
Debug WordPress menu
View functions.php
/**
* Debug WordPress menu
*/
add_action( 'admin_init', 'ns_debug_admin_menu' );
function ns_debug_admin_menu() {
echo '<pre>' . print_r( $GLOBALS[ 'menu' ], TRUE) . '</pre>';
echo '<style> pre{margin-left: 240px;}</style>';
}
@nfsarmento
nfsarmento / functions.php
Created Jun 5, 2019
Allow skype URIs to be used
View functions.php
/**
* Allow skype URIs to be used
*/
if ( ! function_exists( ( 'ns_portfolio_minimal_allow_skype_protocol' ) ) ) {
function ns_portfolio_minimal_allow_skype_protocol( $protocols ) {
$protocols[] = 'skype';
return $protocols;
}
}
View functions.php
//Disable Gutenberg
add_filter( 'use_block_editor_for_post', '__return_false' );
remove_action( 'try_gutenberg_panel', 'wp_try_gutenberg_panel' );
You can’t perform that action at this time.