Skip to content

Instantly share code, notes, and snippets.

View nfsarmento's full-sized avatar

Nuno Sarmento nfsarmento

View GitHub Profile
@nfsarmento
nfsarmento / body.html
Created May 1, 2020 18:37
Video Youtube or Vimeo PopUp
<div class="vpop" data-type="youtube" data-id="6xcG6ttMDVY" data-autoplay='true'>Youtube</div>
<br />
<div class="vpop" data-type="vimeo" data-id="172052320" data-autoplay='true'>Vimeo</div>
<!-- copy this stuff and down -->
<div id="video-popup-overlay"></div>
<div id="video-popup-container">
@nfsarmento
nfsarmento / functions.php
Created April 18, 2020 12:48
Force WordPress CPT portfolio to Have Excerpts
/**
*
* Force WordPress CPT portfolio to Have Excerpts
* Check if $excerpt is empty and if so set post to draft
*/
if ( ! function_exists( 'envelopedlife_mandatory_excerpt' ) ) {
function envelopedlife_mandatory_excerpt($data) {
//change your_post_type to post, page, or your custom post type slug
if ( 'portfolio' == $data['post_type'] ) {
$excerpt = $data['post_excerpt'];
@nfsarmento
nfsarmento / last-modified-admin-columns
Created April 18, 2020 00:40 — forked from acolson/last-modified-admin-columns
WordPress sortable custom admin column for last modified date and user
add_filter( 'manage_edit-post_columns', 'aco_last_modified_admin_column' );
// Create the last modified column
function aco_last_modified_admin_column( $columns ) {
$columns['modified-last'] =__( 'Last Modified', 'aco' );
return $columns;
}
add_filter( 'manage_edit-post_sortable_columns', 'aco_sortable_last_modified_column' );
@nfsarmento
nfsarmento / functions.php
Created April 15, 2020 20:22
WordPress image orientation detection
function ns_single_image_filter($size){
$tn_id = get_post_thumbnail_id( $post->ID );
$img = wp_get_attachment_image_src( $tn_id, $size );
$width = $img[1];
$height = $img[2];
if (has_post_thumbnail($post->ID )){
if ($width > $height){ ?>
<?php the_post_thumbnail($size, array( 'class' => "ns-landscape") );
}else{ ?>
<?php the_post_thumbnail($size, array( 'class' => "ns-portrait") );
@nfsarmento
nfsarmento / functions.php
Created April 15, 2020 15:12
Replaces the default excerpt editor with TinyMCE.
/**
* Replaces the default excerpt editor with TinyMCE.
*/
class NS_Richtext_Excerpt
{
/**
* Replaces the meta boxes.
*
* @return void
*/
@nfsarmento
nfsarmento / quick_edit.js
Created April 15, 2020 01:24 — forked from michael-cannon/quick_edit.js
Working WordPress bulk and quick edit example for a video custom post type. http://aihr.us/wordpress/working-examples-for-wordpress-bulk-and-quick-edit/
// @ref http://rachelcarden.com/2012/03/manage-wordpress-posts-using-bulk-edit-and-quick-edit/
(function($) {
// we create a copy of the WP inline edit post function
var $wp_inline_edit = inlineEditPost.edit;
// and then we overwrite the function with our own code
inlineEditPost.edit = function( id ) {
// "call" the original WP edit function
// we don't want to leave WordPress hanging
$wp_inline_edit.apply( this, arguments );
@nfsarmento
nfsarmento / quick-edit.php
Last active April 15, 2020 01:44 — forked from daronspence/quick-edit.php
Quick Edit Plugin
<?php
/**
* Plugin Name: NS inline edit
* Plugin URL: https://www.nuno-sarmento.com
* Description: Add excerpt to WordPress Posts Quick Edit
* Requires at least: 5.0
* Tested up to: 5.4
* Version: 0.1
* Plugin Author: Nuno Sarmento
* Author URI: https://www.nuno-sarmento.com
@nfsarmento
nfsarmento / cpt.php
Last active April 14, 2020 15:14
How to create a featured post with metabox - WordPress
<?php
# Edit your CPT $args and add the below
'register_meta_box_cb' => 'prfx_featured_meta',
@nfsarmento
nfsarmento / yoast_seo_opengraph_change_image_size.php
Created March 16, 2020 10:33 — forked from amboutwe/yoast_seo_opengraph_change_image_size.php
Code snippet to change or remove OpenGraph output in Yoast SEO. There are multiple snippets in this code.
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/* Change size for Yoast SEO OpenGraph image for all content
* Credit: Yoast Development team
* Last Tested: May 24 2019 using Yoast SEO 11.2.1 on WordPress 5.2.1
*/
add_filter( 'wpseo_opengraph_image_size', 'yoast_seo_opengraph_change_image_size' );
function yoast_seo_opengraph_change_image_size( $string ) {
@nfsarmento
nfsarmento / archive.php
Last active March 11, 2020 14:22
WordPress Custom Post Type Settings page with an editable wp_editor filed to show above CPT archive listings
<?php echo cpt_custom_content( 'photo_competition', 'title' ); ?>
<?php echo cpt_custom_content( 'photo_competition', 'content' ); ?>