Skip to content

Instantly share code, notes, and snippets.

View aldolat's full-sized avatar
🤓
Happy in coding

Aldo Latino aldolat

🤓
Happy in coding
View GitHub Profile
@aldolat
aldolat / functions.php
Last active May 2, 2020 07:38
Add attribute target="_blank" to all links children of "posts-in-sidebar" class.
<?php
/**
* Register scripts.
* Add this function to your functions.php file or to your functions plugin.
*
* @since 1.0.0
*/
function posts_in_sidebar_hacks() {
wp_register_script(
'pis_scripts',

Keybase proof

I hereby claim:

  • I am aldolat on github.
  • I am aldolat (https://keybase.io/aldolat) on keybase.
  • I have a public key whose fingerprint is 3CEA 2AAB 56A7 929A A0E9 2AAA 2E15 B621 E350 BA44

To claim this, I am signing this object:

@aldolat
aldolat / diff.bash
Created September 16, 2017 21:09
Excluding files and folders in diff command
diff -rq -x ".git" -x ".directory" /path/to/first/directory/ /path/to/second/directory/
@aldolat
aldolat / 404-with-posts-in-sidebar.php
Last active June 10, 2017 06:08
Adds a list of posts in a 404 page using Posts in Sidebar
<?php
$request_uri = $_SERVER['REQUEST_URI']; // Returns for example /blog/loremipsum
// Remove trailing slash and take only the word after the last slash
preg_match( '/[^\/]+$/', rtrim( $request_uri, '/' ), $search );
$search = implode( '', $search ); // Returns for example loremipsum
echo do_shortcode('[pissc search="' . $search . '" orderby=title number=5 debug_query="true"]');
@aldolat
aldolat / pis_array_remove_empty_keys.php
Created May 21, 2017 05:34
Remove empty keys from an array recursively.
<?php
/**
* Remove empty keys from an array recursively.
*
* @param array $array The array to be checked.
* @param boolean $make_empty If the output is to return as an empty string.
* @since 1.29
* @see http://stackoverflow.com/questions/7696548/php-how-to-remove-empty-entries-of-an-array-recursively
*/
function pis_array_remove_empty_keys( $array, $make_empty = false ) {
@aldolat
aldolat / jquery-wordpress-widget-events.js
Created May 7, 2017 10:15
jQuery for WordPress events on widgets.
jQuery(document).on('widget-updated', function(event, widget){
var widget_id = jQuery(widget).attr('id');
// any code that needs to be run when a widget gets updated goes here
// widget_id holds the ID of the actual widget that got updated
// be sure to only run the code if one of your widgets got updated
// otherwise the code will be run when any widget is updated
});
jQuery(document).on('widget-added', function(event, widget){
var widget_id = jQuery(widget).attr('id');
@aldolat
aldolat / pis_compare_string_to_array.php
Last active January 8, 2023 11:02
Compare a string and an array and return the common elements as a string.
<?php
/**
* Compare a string and an array and return the common elements as a string.
*
* @param string $string The string to be compared.
* @param array $array The array to be compared.
*
* @return string $output The string containing the common values.
*
@aldolat
aldolat / wp_gist_embed.php
Created April 17, 2017 18:07
Embed a Gist in WordPress using a shortcode.
<?php
/**
* Create the shortcode to embed a Gist.
*
* @example [gist]https://gist.github.com/aldolat/8625342[/gist]
* @since 4.5
*/
function aldolat_gist_embed( $atts, $content = null ) {
extract( shortcode_atts( array(), $atts ) );
@aldolat
aldolat / forkmeribbon_wp_shortcode.php
Last active April 17, 2017 17:59
Create a "Fork me on GitHub" ribbon.
<?php
/**
* Create a "Fork me on GitHub" ribbon.
*
* @example [forkmeribbon url="http://www.example.com" color="red" position="right"]
* @since 1.0
*/
function forkmeribbon_function( $atts ) {
extract( shortcode_atts( array(
'url' => '',
@aldolat
aldolat / functions.php
Last active December 4, 2016 07:32
Remove title attribute and shorten title
<?php
// Add this function to your functions.php file or to your functions plugin.
function posts_in_sidebar_hacks() {
wp_enqueue_script( 'pis-add-hacks', get_template_directory_uri() . '/js/pis-hacks.js', array( 'jquery' ), false, true );
}
add_action( 'wp_enqueue_scripts', 'posts_in_sidebar_hacks' );