Skip to content

Instantly share code, notes, and snippets.

View nfsarmento's full-sized avatar

NS nfsarmento

View GitHub Profile
@nfsarmento
nfsarmento / functions.php
Created July 2, 2020 15:56
Display categories in single-cpt.php
<?php
if ( is_singular('YOUR_CUSTOM_POST_TYPE') ) {
$terms = get_the_terms($post->ID, 'custom_categories');
foreach ($terms as $term) {
$term_link = get_term_link($term, 'custom_categories');
if (is_wp_error($term_link))
continue;
echo '<a href="' . $term_link . '">' . $term->name . '</a>, ';
}
@nfsarmento
nfsarmento / .htaccess
Last active May 29, 2020 23:49
WordPress Apache .htaccess
## Use the code below only if you had enable .htaccess - "AllowOverride All"
## You may need to enable mod_headers on apache - "a2enmod headers"
## The code below goes under the rules that you should have if you are using WordPress
#BEGIN https code
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#BEGIN Block bad hackers
@nfsarmento
nfsarmento / WordPress shortoce to show Custom Post Type .php
Last active September 22, 2023 14:35
WordPress shortoce to show Custom Post Type
<?php
/**
*
* Usage [newscpt posts_per_page="4" term="4"] .
* Change post_type to your CPT name
* Change taxonomy to your taxonomy name
*
*/
// @codingStandardsIgnoreStart
@nfsarmento
nfsarmento / shortcode-button.php
Created May 19, 2020 11:00
WordPress shortcode to show button
<?php
/**
*
* Add a new custom button.
* Usage [custombutton url="https://www.nuno-sarmento.com/" target="self" text="Go To NS"].
*/
// @codingStandardsIgnoreStart
function ns_custom_button_shortcode( $atts, $content = null ) {
// shortcode attributes
@nfsarmento
nfsarmento / single.php
Created May 18, 2020 10:56
Get Related Posts For Custom Post Type by Custom Taxonomy
<?php
// Show related posts.
// Fetch taxonomy terms for current product.
$productterms = get_the_terms( get_the_ID(), 'work_categories' );
if( $productterms ) {
$producttermnames[] = 0;
foreach( $productterms as $productterm ) {
$producttermnames[] = $productterm->name;
}
// Set up the query arguments.
@nfsarmento
nfsarmento / .htaccess
Last active May 16, 2020 15:58
WordPress Security Harden Apache .htaccess
# Prevents directory listing
Options -Indexes
# Deny backup extensions & log files
<Files ~ "(^#.*#|~|\.save|\.sw[op])$">
Order allow,deny
Deny from all
</Files>
#Protect .htaccess From Unauthorized Access
@nfsarmento
nfsarmento / WordPress admin column to print user websites visits.php
Created May 6, 2020 09:49
WordPress admin column to print user websites visits
/*
* Admin user page custom column - Print User Web Visits Column Value
*/
class NSLogin_Counter {
public function init() {
add_action( 'wp_login', array( $this, 'count_user_login' ), 10, 2 );
add_filter( 'manage_users_columns', array( $this, 'add_stats_columns' ) );
add_filter( 'manage_users_custom_column', array( $this, 'fill_stats_columns' ), 10, 3 );
@nfsarmento
nfsarmento / Add SVG support on WordPress .php
Created May 6, 2020 09:42
Add SVG support on WordPress
/**
* Add svg support
*
*/
add_filter( 'wp_check_filetype_and_ext', function( $data, $file, $filename, $mimes) {
global $wp_version;
if( $wp_version == '4.7' || ( (float) $wp_version < 4.7 ) ) {
return $data;
}
$filetype = wp_check_filetype( $filename, $mimes );
@nfsarmento
nfsarmento / bitbucket-pipelines.yml
Created May 5, 2020 13:00 — forked from mcnamee/bitbucket-pipelines.yml
Bitbucket Pipelines - Deploy via FTP to shared hosting
# Installation ---
# 1. In Bitbucket, add $FTP_USERNAME $FTP_PASSWORD and $FTP_HOST as environment variables.
# 2. Commit this file to your repo
# 3. From Bitbucket Cloud > Commits > Commit Number > Run Pipeline > Custom:Init (this will
# push everything and initial GitFTP)
#
# Usage ---
# - On each commit to master branch, it'll push all files to the $FTP_HOST
# - You also have the option to 'init' (from Bitbucket Cloud) - pushes everything and initialises
# - Finally you can also 'deploy-all' (from Bitbucket Cloud) - if multiple deploys fail, you
@nfsarmento
nfsarmento / body.html
Created May 1, 2020 18:37
Video Youtube or Vimeo PopUp
<div class="vpop" data-type="youtube" data-id="6xcG6ttMDVY" data-autoplay='true'>Youtube</div>
<br />
<div class="vpop" data-type="vimeo" data-id="172052320" data-autoplay='true'>Vimeo</div>
<!-- copy this stuff and down -->
<div id="video-popup-overlay"></div>
<div id="video-popup-container">