Skip to content

Instantly share code, notes, and snippets.

View braginteractive's full-sized avatar

Brad Williams braginteractive

View GitHub Profile
@braginteractive
braginteractive / extras.php
Created April 11, 2017 21:45
Add class to Read More link in WordPress
<?php
/**
* Customize the Read More Button
**/
function helpwp_modify_read_more_link() {
return '<a class="more-link btn btn-sm btn-primary" href="' . get_permalink() . '">View Tutorial</a>';
}
add_filter( 'the_content_more_link', 'helpwp_modify_read_more_link' );
@braginteractive
braginteractive / _posts-and-pages.scss
Created April 11, 2017 21:10
WordPress Pagination
/* Posts Navigation */
.pagination {
margin-top: 30px;
justify-content: center;
.page-numbers {
border: 1px solid rgba(0,0,0,.2);
padding: 8px;
border-radius: 3px;
@braginteractive
braginteractive / content.php
Last active April 11, 2017 20:28
Embed responsive YouTube video into WordPress
<div class="entry-video">
<?php
$url = get_post_meta( get_the_ID(), 'helpwp_url', true);
$yt_id = helpwp_youtube_id($url);
if ($url != '') : ?>
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="//www.youtube.com/embed/<?php echo esc_html( $yt_id ); ?>" allowfullscreen></iframe>
</div>
@braginteractive
braginteractive / content-cards.php
Last active April 11, 2017 20:29
Display YouTube thumbnail or Featured image
<?php
$url = get_post_meta( get_the_ID(), 'helpwp_url', true);
$yt_id = helpwp_youtube_id($url);
if ($url != '') : ?>
<a href="<?php the_permalink(); ?>">
<img alt="<?php the_title(); ?>" class="card-img-top" src="https://img.youtube.com/vi/<?php echo esc_html( $yt_id ); ?>/maxresdefault.jpg">
</a>
<?php else : ?>
@braginteractive
braginteractive / extras.php
Last active April 11, 2017 20:30
Get YouTube video ID from URL
<?php
/**
* Get the ID of a YouTube Video
**/
function helpwp_youtube_id($url){
/*
* type1: http://www.youtube.com/watch?v=9Jr6OtgiOIw
* type2: http://www.youtube.com/watch?v=9Jr6OtgiOIw&feature=related
* type3: http://youtu.be/9Jr6OtgiOIw
*/
@braginteractive
braginteractive / content-page.php
Created April 11, 2017 17:31
Display sample meta boxes on page
<?php
$text = get_post_meta( get_the_ID(), '_yourprefix_text', true );
$email = get_post_meta( get_the_ID(), '_yourprefix_email', true );
$url = get_post_meta( get_the_ID(), '_yourprefix_url', true );
echo esc_html( $text );
echo is_email( $email );
echo esc_url( $url );
?>
@braginteractive
braginteractive / functions.php
Created April 11, 2017 17:24
Call meta-boxes.php file
/**
* Meta Boxes.
*/
require get_template_directory() . '/inc/meta-boxes.php';
@braginteractive
braginteractive / example-meta-box.php
Created April 11, 2017 17:20
CMB2 example meta boxes
add_action( 'cmb2_admin_init', 'cmb2_sample_metaboxes' );
/**
* Define the metabox and field configurations.
*/
function cmb2_sample_metaboxes() {
// Start with an underscore to hide fields from custom fields list
$prefix = '_yourprefix_';
/**
@braginteractive
braginteractive / content-cards.php
Created April 11, 2017 17:04
Add Featured Image to WordPress theme.
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'full', array('class' => 'card-img-top')); ?>
</a>
@braginteractive
braginteractive / extras.php
Created April 7, 2017 05:24
WordPress Filter to change the Custom Logo class
/**
* Changes the class on the custom logo in the header.php
*/
function helpwp_custom_logo_output( $html ) {
$html = str_replace('custom-logo-link', 'navbar-brand', $html );
return $html;
}
add_filter('get_custom_logo', 'helpwp_custom_logo_output', 10);