Skip to content

Instantly share code, notes, and snippets.

View adamcapriola's full-sized avatar

Adam Capriola adamcapriola

View GitHub Profile
# Ignore everything #
**
!wp-content/
wp-content/**
!wp-content/themes/
!wp-content/plugins/
wp-content/themes/**
wp-content/plugins/**
# Add two rules for each Theme or Plugin you want to include:
@adamcapriola
adamcapriola / tinymce-add-formats.md
Created August 7, 2019 16:34 — forked from psorensen/tinymce-add-formats.md
Wordpress/TinyMCE - Add elements to formats dropdown

Adding Elements to the TinyMCE Format Dropdown

On a recent migration project, one of the requirements was to add a few blockquote styles to the TinyMCE dropdown list to match the editorial process of the old CMS. Wordpress provides a filter to add a secondary or tetriary dropdown, but if you only have a couple additional elements, it seems like bad UX to seperate it from the original dropdown.

Going off a tip from Chancey Mathews, I realized that Wordpress does not send a argument for block_formats when initializing TinyMCE, thus relying on the defaults. By adding this argument to the tiny_mce_before_init filter, we can add in our extra elements*:

* Note: since we're overriding the defaults, we need to include the original elements (p, h1-h6..etc)

function mce_formats( $init ) {
@adamcapriola
adamcapriola / query-posts-views.php
Last active January 30, 2019 18:59
Example query for popular posts (i.e., posts with most views)
<?php
/**
* Example query: Posts ordered by most views
*
*/
$args = (
'meta_key' => 'views',
'orderby' => 'meta_value_num',
'order' => 'DESC',
);
jQuery(document).ready(function(e) {
e.ajax({
method: "POST",
url: save_views.ajax_url,
data: {
post_id: save_views.post_id,
nonce: save_views.nonce,
action: "save_views"
}
});
@adamcapriola
adamcapriola / ac-ajax-save-views.php
Last active October 26, 2021 18:56
Save Jetpack "Site Stats" Pageviews as Post Meta
<?php
/**
* Save Jetpack views as post meta: Process Ajax request
*
*/
add_action( 'wp_ajax_save_views', 'ac_ajax_save_views' );
add_action( 'wp_ajax_nopriv_save_views', 'ac_ajax_save_views' );
function ac_ajax_save_views() {
@adamcapriola
adamcapriola / source-links-images.css
Last active January 19, 2019 17:46
CSS for images with source links
@adamcapriola
adamcapriola / source-link-non-captioned-images.php
Last active January 19, 2019 17:24
Filter non-captioned images to include source link
@adamcapriola
adamcapriola / source-link-captioned-images.php
Last active January 19, 2019 17:23
Filter captioned images to include source link
@adamcapriola
adamcapriola / add-save-attachment-source-fields.php
Last active January 19, 2019 17:47
Attachment source fields (add and save)
<?php
/**
* Attachment source fields
* @link https://kaspars.net/?p=3203
* @link https://www.billerickson.net/?p=3555
*
*/
// Add fields
add_filter( 'attachment_fields_to_edit', 'ac_attachment_fields_to_edit_source', 10, 2 );
@adamcapriola
adamcapriola / safari-placeholder-line-height-fix.css
Last active January 18, 2019 19:28
Fix Line Height for Input Placeholders in Safari
.search-form input[type=search] {
line-height: revert;
}