Skip to content

Instantly share code, notes, and snippets.

View monecchi's full-sized avatar

Adriano Monecchi monecchi

View GitHub Profile
//Register Meta with Rest API
add_action( 'rest_api_init', 'prefix_register_custom_meta' );
function prefix_register_custom_meta() {
register_rest_field(
'post',
'_prefix_url',
array(
'get_callback' => 'prefix_get_custom_meta',
'update_callback' => null,
'schema' => null,
/**
* Retrieve custom meta for use in the REST API
*
* @param array $object Details of current post.
* @param string $field_name Name of field.
* @param WP_REST_Request $request Current request
*
* @return mixed
*/
function prefix_get_custom_meta( $object, $field_name, $request ) {
@monecchi
monecchi / wordpress-seo-keywords-bs.php
Created June 15, 2016 20:26 — forked from robneu/wordpress-seo-keywords-bs.php
WordPress SEO without a plugin is complete crap. Let's break it down one function at a time.
<?php
function basic_wp_seo() {
global $page, $paged, $post;
$default_keywords = 'wordpress, plugins, themes, design, dev, development, security, htaccess, apache, php, sql, html, css, jquery, javascript, tutorials'; // customize
$output = '';
// description
$seo_desc = get_post_meta($post->ID, 'mm_seo_desc', true);
$description = get_bloginfo('description', 'display');
$pagedata = get_post($post->ID);
@monecchi
monecchi / dcWPFunctions.html
Created June 15, 2016 20:24 — forked from dcondrey/dcWPFunctions.html
My collection of custom functions for use with WP. Manipulating post content and titles, article content and titles, seo, cleanup, etc, misc..
<?php
/**
* Limit previous/next post title character length and append a ellipsis if trunicated
*/
$previous_post = get_adjacent_post( false, '', true );
$next_post = get_adjacent_post( false, '', false );
$previous_post_title= get_the_title($previous_post);
$next_post_title = get_the_title($next_post);
$max_length = 75;
$previous_post_length = strlen($previous_post_title);
function custom_taxonomies_terms_links() {
global $post, $post_id;
// get post by post id
$post = &get_post($post->ID);
// get post type by post
$post_type = $post->post_type;
// get post type taxonomies
$taxonomies = get_object_taxonomies($post_type);
$out = "<ul>";
foreach ($taxonomies as $taxonomy) {
@monecchi
monecchi / wp-related-by-category
Created June 14, 2016 19:39 — forked from troutacular/wp-related-by-category
WordPress Related by Category
@monecchi
monecchi / wp-query-ref.php
Created June 9, 2016 23:13 — forked from luetkemj/wp-query-ref.php
WP: Query $args
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/query.php
*/
$args = array(
@monecchi
monecchi / functions.php
Created June 8, 2016 12:58 — forked from billerickson/functions.php
Use the built-in post counter
<?php
/**
* Use the built-in post counter
*
* Sometimes you'll want to keep track of which post you're on in a loop.
* Some people create their own $loop_counter (ex: Genesis, https://gist.github.com/4675237 ).
* There's a better way! A loop counter is built into $wp_query. Ex:
*
* global $wp_query;
* echo $wp_query->current_post
@monecchi
monecchi / aq-portfolio-block.php
Last active June 8, 2016 12:08 — forked from contempoinc/aq-portfolio-block.php
Portfolio Page Aqua Builder Block
<?php
/** A simple text block **/
if(!class_exists('AQ_Portfolio_Block')) {
class AQ_Portfolio_Block extends AQ_Block {
//set and create block
function __construct() {
$block_options = array(
'name' => 'Portfolio',
@monecchi
monecchi / wp_rss_feed.php
Created June 4, 2016 21:22 — forked from nickeforsberg/wp_rss_feed.php
Multiple Custom Post Types to Wordpress main RSS Feed.
// Add custom post types main RSS feed.
function wp_rss_feed( $query ) {
if ( $query->is_feed() )
$query->set( 'post_type', array( 'post', 'events', 'books' ) );
return $query;
}
add_filter( 'pre_get_posts', 'wp_rss_feed' );