Skip to content

Instantly share code, notes, and snippets.

View wpexplorer's full-sized avatar
✍️
We create themes & plugins and run a popular blog about WordPress.

WPExplorer wpexplorer

✍️
We create themes & plugins and run a popular blog about WordPress.
View GitHub Profile
@wpexplorer
wpexplorer / gist:6416006
Last active December 22, 2015 04:19
Add slug to menu ID for pages in WordPress menu
add_filter('nav_menu_link_attributes' , 'att_add_menu_id', 3, 10);
if ( !function_exists( 'att_add_menu_id') ) {
function att_add_menu_id($atts, $item, $args) {
if( 'page' == $item->object ){
$id = $item->object_id;
$id = 'page-'. esc_attr( basename( get_permalink( $id ) ) );
$atts['id'] = $id;
}
return $atts;
}
@wpexplorer
wpexplorer / gist:6574282
Created September 15, 2013 20:58
Simple WordPress login/logout shortcode
if ( ! function_exists('wpex_loginout_shortcode') ) {
function wpex_loginout_shortcode( $atts ) {
extract( shortcode_atts( array(
'login_url' => wp_login_url(),
'log_in_text' => __( 'log in', 'wpex' ),
'log_out_text' => __( 'log out', 'wpex' ),
), $atts ) );
if ( is_user_logged_in() ) {
$url = wp_logout_url( home_url() );
return '<a href="'. $url .'" title="'. $log_out_text .'">'. $log_out_text .'</a>';
@wpexplorer
wpexplorer / gist:6613334
Created September 18, 2013 18:25
Open Graph Video URL For Facebook - WordPress Function
<?php
// Add video open graph metatag
add_action( 'wp_head', 'wpex_fb_video_opengraph');
function wpex_fb_video_opengraph() {
if ( is_singular( 'post' ) ) {
global $post;
$output='';
$postid = $post->ID;
$format = get_post_format( $post_id );
if ( $format !== 'video' ) return; // not video post format, so exit
@wpexplorer
wpexplorer / gist:6924897
Created October 10, 2013 20:19
WPML Shortcode for WordPress
/***WPML Translation Shortcode****/
if(! function_exists('wpex_wpml_lang_translate')) {
function wpex_wpml_lang_translate( $atts, $content = null ) {
extract(shortcode_atts(array(
'lang' => '',
), $atts));
$lang_active = ICL_LANGUAGE_CODE;
if($lang == $lang_active){
@wpexplorer
wpexplorer / gist:7149524
Created October 25, 2013 04:43
Portfolio first cat link
// Displays the first category of a given portfolio
if ( ! function_exists( 'wpex_portfolio_first_cat' ) ) {
function wpex_portfolio_first_cat($postid=false) {
global $post;
$postid = $postid ? $postid : $post->ID;
$cats = get_the_terms( $postid, 'portfolio_category' );
$output = '';
if( $cats ) {
$count=0;
foreach( $cats as $cat ) {
@wpexplorer
wpexplorer / gist:7176010
Created October 26, 2013 23:46
Font Awesome 4.0 PHP Array
array( 'glass','music','search','envelope-o','heart','star','star-o','user','film','th-large','th','th-list','check','times','search-plus','search-minus','power-off','signal','gear','trash-o','home','file-o','clock-o','road','download','arrow-circle-o-down','arrow-circle-o-up','inbox','play-circle-o','rotate-right','refresh','list-alt','lock','flag','headphones','volume-off','volume-down','volume-up','qrcode','barcode','tag','tags','book','bookmark','print','camera','font','bold','italic','text-height','text-width','align-left','align-center','align-right','align-justify','list','dedent','indent','video-camera','picture-o','pencil','map-marker','adjust','tint','edit','share-square-o','check-square-o','move','step-backward','fast-backward','backward','play','pause','stop','forward','fast-forward','step-forward','eject','chevron-left','chevron-right','plus-circle','minus-circle','times-circle','check-circle','question-circle','info-circle','crosshairs','times-circle-o','check-circle-o','ban','arrow-left','arrow
@wpexplorer
wpexplorer / gist:7323764
Created November 5, 2013 18:33
// Displays the first category of a given portfolio
if ( ! function_exists( 'wpex_portfolio_first_cat' ) ) {
function wpex_portfolio_first_cat($postid=false) {
global $post;
$postid = $postid ? $postid : $post->ID;
$cats = get_the_terms( $postid, 'portfolio_category' );
$output = '';
if( $cats ) {
$count=0;
foreach( $cats as $cat ) {
$count++;
@wpexplorer
wpexplorer / gist:7323824
Created November 5, 2013 18:37
// Displays the first category of a given portfolio post, but show all cateegories on the single post
function wpex_portfolio_first_cat($postid=false) {
global $post;
$postid = $postid ? $postid : $post->ID;
$cats = get_the_terms( $postid, 'portfolio_category' );
$output = '';
if( $cats ) {
$cats_count = count($cats);
if ( is_singular('portfolio') ) {
$count=0;
foreach( $cats as $cat ) {
@wpexplorer
wpexplorer / gist:7361964
Created November 7, 2013 21:14
Blog next/prev
<ul class="blog-post-pagination clr">
<?php next_post_link( '<li class="post-prev">%link</li>', '<span class="icon-arrow-left"></span>', false); ?>
<?php previous_post_link( '<li class="post-next">%link</li>', '<span class="icon-arrow-right"></span>', false ); ?>
</ul><!-- .blog-post-pagination -->
@wpexplorer
wpexplorer / gist:7442329
Created November 13, 2013 02:02
field spacing
<?php
class ReduxFramework_spacing extends ReduxFramework{
/**
* Field Constructor.
*
* Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function
*
* @since ReduxFramework 1.0.0
*/