Skip to content

Instantly share code, notes, and snippets.

View adamcapriola's full-sized avatar

Adam Capriola adamcapriola

View GitHub Profile
# Ignore everything #
# Add two rules for each Theme or Plugin you want to include:
adamcapriola /
Created August 7, 2019 16:34 — forked from psorensen/
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 / query-posts-views.php
Last active January 30, 2019 18:59
Example query for popular posts (i.e., posts with most views)
* Example query: Posts ordered by most views
$args = (
'meta_key' => 'views',
'orderby' => 'meta_value_num',
'order' => 'DESC',
jQuery(document).ready(function(e) {
method: "POST",
url: save_views.ajax_url,
data: {
post_id: save_views.post_id,
nonce: save_views.nonce,
action: "save_views"
adamcapriola / ac-ajax-save-views.php
Last active October 26, 2021 18:56
Save Jetpack "Site Stats" Pageviews as Post Meta
* 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 / source-links-images.css
Last active January 19, 2019 17:46
CSS for images with source links
adamcapriola / source-link-non-captioned-images.php
Last active January 19, 2019 17:24
Filter non-captioned images to include source link
adamcapriola / source-link-captioned-images.php
Last active January 19, 2019 17:23
Filter captioned images to include source link
adamcapriola / add-save-attachment-source-fields.php
Last active January 19, 2019 17:47
Attachment source fields (add and save)
* Attachment source fields
* @link
* @link
// Add fields
add_filter( 'attachment_fields_to_edit', 'ac_attachment_fields_to_edit_source', 10, 2 );
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;