Skip to content

Instantly share code, notes, and snippets.

View Jany-M's full-sized avatar
🎯
Focusing

Jany Martelli Jany-M

🎯
Focusing
View GitHub Profile
@Jany-M
Jany-M / WP_hide_trash_link_check_role_move_last.php
Created April 8, 2016 14:49
[WordPress] Hide Trash link depending on User Role and place it for last
@Jany-M
Jany-M / WP_view_link_new_tab.php
Created April 8, 2016 14:44
[WordPress] View link opens Post in a new Tab
@Jany-M
Jany-M / WP_extend_duplicate_content_create_clones_and_identical_children.php
Created April 8, 2016 14:38
[WordPress[ Extend Duplicate Content functions to create clones and identical post children
<?php
// Requires the duplicate_content() function
// https://gist.github.com/Jany-M/ba36a0499e4fb505105e
// Add link to create a cloned CHILD of this post, to action list for post_row_actions
function duplicate_content_link( $actions, $post ) {
global $typenow;
$user_id = get_current_user_id();
$user_data = get_userdata($user_id);
@Jany-M
Jany-M / WP_automatically_rename_slug_on_post_save.php
Last active June 6, 2021 16:29
[WordPress] Automatically rename post slug on post save
<?php
// Change & Save New Permalink if post title was changed
function update_slug_on_edit( $data, $postarr ) {
global $post;
$id = $post->ID;
$status = $post->post_status;
$cpt = get_post_type($id);
$parent = $post->post_parent;
@Jany-M
Jany-M / WP_gists_as_wordpress_posts.php
Last active June 6, 2021 16:29
[WordPress] Display Gists as if they were real WordPress Posts (without saving them to database)
<?php
// This will display Gists as if they were real WP posts, so you can display them mixed with real ones too
// This will NOT add the Gists as real posts in your DB, you won't see them in your backend
/* --------------------------------------
|
| Real Posts Loop
|
|---------------------------------------*/
@Jany-M
Jany-M / WP_flush_cache_and_transients.php
Last active January 20, 2025 12:13
[WordPress] Flush Object Cache (Memcached) & Transients - Admin buttons
<?php
// Flush Cache from Admin bar
function flush_memcache_button() {
global $wp_admin_bar;
// If User isnt even logged in or if admin bar is disabled
if ( !is_user_logged_in() || !is_admin_bar_showing() )
return false;
@Jany-M
Jany-M / WP_get_facebook_page_likes.php
Last active February 29, 2016 23:01
[WordPress] Get Facebook Page Likes and Cache them
<?php
// Get a user Access Token (or Page Token if you're the page admin)
// https://developers.facebook.com/tools/explorer/145634995501895/
function get_fb_likes($what) {
$token = 'your_token_here';
//delete_transient('cached_fb');
if(false === ( $cached_fb_results = get_transient( 'cached_fb' ))) {
$json_url = 'https://graph.facebook.com/v2.5/'.$what.'?fields=likes&access_token='.$token;
$json = file_get_contents($json_url);
@Jany-M
Jany-M / WP_custom_column_with_cloning.php
Last active June 6, 2021 16:30
[WordPress] Custom column with clone button to other custom post type
<?php
// Duplicate function
function duplicate_content(){
global $wpdb;
if (! ( isset( $_GET['post']) || isset( $_POST['post']) || ( isset($_REQUEST['action']) && 'duplicate_content' == $_REQUEST['action'] ) ) ) {
wp_die('No post to duplicate has been supplied!');
}
// Get original ID
@Jany-M
Jany-M / WP_query_repeater.php
Last active February 2, 2016 18:05
[WordPress] Repeat a Query/Loop with automatic offset, query caching through transients and cutom post type, no children, order by title
<?php
$i = 0;
$num = 30;
$offset = 30;
$cpt = 'rate-plan';
$qty = '1,2,3,4,5,6,7,8,9,10,11,12';
$times = explode(',', $qty);
foreach($times as $item) {
$i++;
@Jany-M
Jany-M / WP_remove_product_name_woocommerce_breadcrumbs.php
Created November 30, 2015 12:54
[WordPress] Remove Product Name & URL from WooCommerce Breadcrumbs
<?php
// In your theme, make a new folder woocommerce/global/
// Add this function in a file called breadcrumbs.php, in that folder
// or integrate the existing function accordingly.
/**
* Shop breadcrumb
*
* @author WooThemes
* @package WooCommerce/Templates