Skip to content

Instantly share code, notes, and snippets.

View adamcapriola's full-sized avatar

Adam Capriola adamcapriola

View GitHub Profile
@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',
);
@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 ) {
# 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: