Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View yoren's full-sized avatar

Yoren Chang yoren

View GitHub Profile
@yoren
yoren / main-featured-image.html
Last active August 29, 2015 14:16
Category Pages In AngularJS WordPress Theme
@yoren
yoren / functions.php
Last active August 29, 2015 14:16
Add target attribute to image link
<?php
//...
function my_add_link_target( $html ) {
$html = preg_replace( '/(<a.*")>/', '$1 target="_self">', $html );
return $html;
}
add_filter( 'image_send_to_editor', 'my_add_link_target', 10 );
<?php
/**
* Load the template data from a file (file must be .html or .htm )
*/
//load from child theme or parent theme
$file = 'template.html';
echo caldera_metaplate_from_file( $file, $post_id );
//or use absolute patth
//$file = __FILE__ . '/template.html';
@yoren
yoren / scripts.js
Last active August 29, 2015 14:15
Setting Page Title Dynamically In AngularJS WordPress Theme
//...
//Main controller
app.controller('Main', ['$scope', '$http', function($scope, $http) {
$http.get('wp-json/posts/').success(function(res){
$scope.posts = res;
document.querySelector('title').innerHTML = 'Home | AngularJS Demo Theme';
});
}]);
@yoren
yoren / index.php
Last active August 23, 2016 04:59
Making WordPress Admin Bar Work With AngularJS Theme
<!DOCTYPE html>
<html>
<head>
<base href="/jsonapi/">
<title>AngularJS Demo Theme</title>
<?php wp_head(); ?>
</head>
<body>
<div id="page" ng-app="app">
<header>
@yoren
yoren / content.html
Last active August 29, 2015 14:14
AngularJS WordPress Theme: Using Slug In Permalink To Get Post
<h1 ng-bind-html="post.title"></h1>
<div ng-bind-html="post.content"></div>
@yoren
yoren / content.php
Last active August 29, 2015 14:14
Move page links on top of share buttons in Ryu
<div class="entry-content clear">
<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'ryu' ) ); ?>
</div><!-- .entry-content -->
@yoren
yoren / content.php
Created February 1, 2015 05:12
A snippet from Ryu
<div class="entry-content clear">
<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'ryu' ) ); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'ryu' ) . '</span>',
'after' => '</div>',
'link_before' => '<span>',
'link_after' => '</span>',
) );
?>
@yoren
yoren / fancy-hands
Created January 29, 2015 09:00
A script to Fancy Hands to search for freelance web developers
Find me 5 "freelance" web developers in [Location]:
1. the quality of their work should be equal or better than [a link to a website of one of my interviewees]
2. so they must have a website with their portfolio
3. can be web designers who can code (front-end development)
4. They must work solo, that means they'll use "About me" rather than "About us" on their websites.
@yoren
yoren / function.php
Created January 22, 2015 06:36
Intercepting posts in WP
<?php
function my_pre_get_posts( $query ) {
if ( ! is_user_logged_in() ) {
$query->set( 'post_type', '404' ); // Do something that you'll never get results
return;
}
}
add_action( 'pre_get_posts', 'my_pre_get_posts' );