Skip to content

Instantly share code, notes, and snippets.

@isotrope
isotrope / for-the-console.js
Last active August 29, 2015 14:14
Trigger your own WP pointers anytime!
// Open up your dev tools console and simply paste this in
// You can change the different variables to suit your needs
// You have to enqueue the script and style, though (see below)
jQuery(document).ready(function ($) {
var pointerTitle = 'My Pointer Title',
pointerContent = 'This is the content of the pointer<br />You can also add Line breaks.',
htmlPointerContent = '<h3>' + pointerTitle + '</h3><p>' + pointerContent + '</p>';
// Simply find the selector you want to target
@isotrope
isotrope / prep-my-meta.php
Created February 6, 2015 17:34
Getting all our Meta Ducks in a row.
<?php
/**
* Build an array object out of basic WP_POST info as well as the meta_keys we want
*
* @param WP_POST $post_object
* @param string|array $expected_meta_keys
*
* @return array
*/
public static function prep_my_wp_object( WP_POST $post_object, $expected_meta_keys ) {
@isotrope
isotrope / select-all-the-selected.php
Created February 10, 2015 21:08
selected( $selected, $current, $echo);
<?php
/**
* selected( $selected, $current, $echo);
*
* http://codex.wordpress.org/Function_Reference/selected
*/
foreach ( $users as $user ) {
echo '<option value="' . $user->id . '" ' . selected( $prop_photographe, $user->ID, false ) . '>' . $user->data->display_name . '</option>';
}
@isotrope
isotrope / dont-strip-iframes.php
Created February 18, 2015 20:14
Allow iFrame code to be entered in TinyMCE
<?php
/**
* Below code could be placed inside your functions.php file
*
* Below is based on
* http://codex.wordpress.org/Plugin_API/Filter_Reference/tiny_mce_before_init
* and various places like
* https://www.leighton.com/blog/stop-tinymce-in-wordpress-3-x-messing-up-your-html-code
* http://redstarwebdevelopment.com/2011/07/15/iframes-in-wordpress/
* http://www.lmhproductions.com/52/wordpress-tincymce-editor-removes-attributes/
(function ($) {
$(document).ready(function () {
var icons = {
header : "ui-icon-circle-arrow-e",
activeHeader: "ui-icon-circle-arrow-s"
},
$accordion = $("#accordion");
$accordion.accordion({
@isotrope
isotrope / add-shortcode-column.php
Last active August 29, 2015 14:16
Add an extra column for a specific Custom Post Type. Echo a shortcode, ready to copy-paste by the user.
<?php
/**
* Adds a shortcode column for a CPT
*
* In this example, my CPT's slug is ISO_SLIDER
*
* Uses
* http://codex.wordpress.org/Plugin_API/Filter_Reference/manage_$post_type_posts_columns
* http://codex.wordpress.org/Plugin_API/Action_Reference/manage_$post_type_posts_custom_column
*
@isotrope
isotrope / functions.php
Last active August 29, 2015 14:16
Change the label for Taxonomy edit screens. (Instead of "Name")
function iso_enqueue_my_awesome_admin_scripts( $hook ) {
// First argument is simply to give it a "name".
wp_enqueue_script( 'iso-custom-admin-scripts', get_template_directory_uri() . '/iso-admin-scripts.js', array('jquery') );
}
add_action( 'admin_enqueue_scripts', 'iso_enqueue_my_awesome_admin_scripts' );
@isotrope
isotrope / acoleman-loop.php
Created March 12, 2015 17:39
Commented version of Alex Coleman's loop
<?php
// In case we need to re-use $prefix somewhere, declaring it here could diminish the chances of a typo
$prefix = '_awc_';
// Get the post meta named '_awc_demo' for 'this' post
// Post_meta can be saved as an array, adding 'true' at the end will result in fetching only one.
// It also means that you don't need to do $entries[0] (index 0 inside $entries) to get what you want
$entries = get_post_meta( get_the_ID(), $prefix . 'demo', true );
// get_post_meta could return 'false', or a blank space, or...
@isotrope
isotrope / marrymi-equal-footer-cols.js
Last active August 29, 2015 14:18
Create equal height columns.
@isotrope
isotrope / example-menu-item.css
Last active January 22, 2025 22:04
Add (a) Polylang switcher menu item(s) to any menu.
/*
Example CSS of how I was showing one OR the other, based on brwoser-width
*/
@media (max-width: @grid-float-breakpoint-max) {
.language-code {
display: none;
}
}