Skip to content

Instantly share code, notes, and snippets.

View thiagoeliasr's full-sized avatar
🏠
Working from home

Thiago Elias thiagoeliasr

🏠
Working from home
View GitHub Profile
<?
$yourTaxonomySlugHere = get_the_terms($post->ID, 'yourTaxonomySlugHere');
if ($terms) :
foreach ($terms as $term) :
echo $term->name;
endforeach;
endif;
?>
@thiagoeliasr
thiagoeliasr / cross-domain.php
Last active September 11, 2015 16:59 — forked from brunomonteiro3/cross-domain.php
Allow Cross-domain requests on Wordpress
add_action( 'init', 'handle_preflight' );
function handle_preflight() {
header("Access-Control-Allow-Origin: " . get_http_origin());
header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");
header("Access-Control-Allow-Credentials: true");
if ( 'OPTIONS' == $_SERVER['REQUEST_METHOD'] ) {
status_header(200);
exit();
@thiagoeliasr
thiagoeliasr / strip_tags.js
Last active September 11, 2015 19:51 — forked from muhittin/strip_tags.js
strip_tags for Javascript
var text = '<div class="foo">bar</div>';
text.replace(/(<([^>]+)>)/ig,""); // Returns: bar
@thiagoeliasr
thiagoeliasr / featured-thumbnail-column.php
Created October 17, 2015 14:42 — forked from brunomonteiro3/featured-thumbnail-column.php
Show the featured image from each post on Wordpress dashboard.
@thiagoeliasr
thiagoeliasr / Mark parent navigation active when on custom post type single page Mark (highlight) custom post type parent as active item in Wordpress Navigation.When you visit a custom post type's single page, the parent menu item (the post type archive) isn't marked as active. This code solves it by comparing the slug of the current post type with the navigation items, and adds a class accordingly.
<?php
add_action('nav_menu_css_class', 'add_current_nav_class', 10, 2 );
function add_current_nav_class($classes, $item) {
// Getting the current post details
global $post;
// Getting the post type of the current post
@thiagoeliasr
thiagoeliasr / delete-all-woocommerce-products.php
Created October 21, 2018 17:49 — forked from mikaelz/delete-all-woocommerce-products.php
Remove all WooCommerce products from database via SQL
<?php
require dirname(__FILE__).'/wp-blog-header.php';
$wpdb->query("DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%')");
$wpdb->query("DELETE FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%'");
$wpdb->query("DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy)");
$wpdb->query("DELETE FROM wp_term_relationships WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'))");
$wpdb->query("DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'))");
$wpdb->query("DELETE FROM wp_posts WHERE post_type IN ('product','product_variation')");
@thiagoeliasr
thiagoeliasr / gist:b5979496bf2c3d3d7685c47fcf0489d0
Created July 28, 2019 18:52 — forked from jagregory/gist:710671
How to move to a fork after cloning
So you've cloned somebody's repo from github, but now you want to fork it and contribute back. Never fear!
Technically, when you fork "origin" should be your fork and "upstream" should be the project you forked; however, if you're willing to break this convention then it's easy.
* Off the top of my head *
1. Fork their repo on Github
2. In your local, add a new remote to your fork; then fetch it, and push your changes up to it
git remote add my-fork [email protected]
@thiagoeliasr
thiagoeliasr / remove-node-modules.md
Created August 11, 2019 18:45 — forked from lmcneel/remove-node-modules.md
How to remove node_modules after they have been added to a repo

How to remove node_modules

  1. Create a .gitignore file in the git repository if it does not contain one

touch .gitignore 2. Open up the .gitignore and add the following line to the file

node_modules 3. Remove the node_modules folder from the git repository

@thiagoeliasr
thiagoeliasr / extractTranslationStrings.php
Created February 8, 2021 18:43 — forked from mariuskubilius/extractTranslationStrings.php
Laravel artisan command to extract translation strings from templates and add them into {language}.json file for localization.
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
class extractTranslationStrings extends Command
{