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_PF_custom_classes.php
Last active August 29, 2015 14:24
[WordPress] Print Friendly Plugin Template Add-On - Add custom classes inside nested iFrames for customization based on Post Type
<?php if(is_singular('slug-of-post-type')) :
global $post;
$p_type = get_post_type(get_the_ID());
?>
<script type="text/javascript">
jQuery(document).ready(function() {
$( ".printfriendly a" ).click(function() {
$("#pf-core").load(function() {
setTimeout( function () {
//console.log( $('#pf-core').contents().find('iframe').contents().find('#pf-print-area') );
@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_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_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_all_posts_default.php
Created April 8, 2016 14:54
[WordPress] Go to All Posts by default, not Mine
<?php
// Go to All posts by default, not Mine
function go_to_all() {
global $typenow;
// Use this if you need this only on specific post types
/*if( 'post' !== $typenow )
return;*/
@Jany-M
Jany-M / check_h3_tags.php
Created August 1, 2016 15:56
[WP] Check content for h3 tags
<?php
// Check content for h3
$doc = new DOMDocument;
$doc->loadHTML(get_the_content(get_the_ID()));
$titles = $doc->getElementsByTagName('h3');
//var_dump($titles); // int
// Prints the content
if( !is_null($titles->item(0)) ) {
@Jany-M
Jany-M / wp_posts.reset.sql
Created August 5, 2016 20:07 — forked from abrudtkuhl/wp_posts.reset.sql
Reset Auto_Increment in WordPress Posts table
/*DELETE FROM wp_posts;
DELETE FROM wp_postmeta;*/
TRUNCATE TABLE wp_posts;
TRUNCATE TABLE wp_postmeta;
@Jany-M
Jany-M / wp_gallery_shortcode_url_parser.php
Last active August 19, 2016 18:05
[WP] Shortcode for a custom Swiper gallery, extract & convert plain text image urls from WordPress post content
@Jany-M
Jany-M / fixed_width_columns_table.html
Created September 1, 2016 14:34
[HTML] Fixed column width table
<table style="table-layout: fixed;">
<colgroup>
<col span="1" style="width: 10%;">
<col span="1" style="width: 10%;">
<col span="1" style="width: 40%;">
<col span="1" style="width: 40%;">
</colgroup>
<tbody>
@Jany-M
Jany-M / wp_extract_slider_from_post.php
Last active December 7, 2016 23:03
[WP] Parse content for shortcode, extract & show it somewhere else, delete it from content
<?php
/* Example with Visual Composer and an add-on for Slides
|
| We want to remove the slider from the post content,
| while keeping it in the backend post editor VC content,
| then place it somewhere else, like the header.
|
| In our case, the slider always sits at the top of the
| post content editor, as first item, in its own row.