Skip to content

Instantly share code, notes, and snippets.

@Siyanda
Created January 18, 2015 21:01
Show Gist options
  • Select an option

  • Save Siyanda/400920a68e7cd8febd52 to your computer and use it in GitHub Desktop.

Select an option

Save Siyanda/400920a68e7cd8febd52 to your computer and use it in GitHub Desktop.
css-tricks snipets
// detect and embed gists
<?php
// [gist id="ID" file="FILE"]
function gist_shortcode($atts) {
return sprintf(
'<script src="https://gist.github.com/%s.js%s"></script>',
$atts['id'],
$atts['file'] ? '?file=' . $atts['file'] : ''
);
} add_shortcode('gist','gist_shortcode');
// Remove this function if you don't want autoreplace gist links to shortcodes
function gist_shortcode_filter($content) {
return preg_replace('/https:\/\/gist.github.com\/([\d]+)[\.js\?]*[\#]*file[=|_]+([\w\.]+)(?![^<]*<\/a>)/i', '[gist id="${1}" file="${2}"]', $content );
} add_filter( 'the_content', 'gist_shortcode_filter', 9);
?>
// Remove Admin Bar For Subscribers
add_action('set_current_user', 'cc_hide_admin_bar');
function cc_hide_admin_bar() {
if (!current_user_can('edit_posts')) {
show_admin_bar(false);
}
}
// Apply Custom CSS to Admin Area
add_action('admin_head', 'my_custom_fonts');
function my_custom_fonts() {
echo '<style>
body, td, textarea, input, select {
font-family: "Lucida Grande";
font-size: 12px;
}
</style>';
}
// WordPress loop
<?php
get_header();
if (have_posts()) : while (have_posts()) : the_post();
?>
// Admin only code
<?php if (current_user_can("manage_options")) : ?>
<a href="<?php echo bloginfo("siteurl") ?>/wp-admin/">Admin</a>
<?php edit_post_link(‘Edit’, ”, ”); ?>
<?php endif; ?>
// code here, get contents
// End WordPress loop
<?php endwhile; else: ?>
Sorry, no pages matched your criteria.
<?php endif; get_footer(); ?>
// Login/Logout and User Welcome
<div id="user-details">
<?php
if (is_user_logged_in()) {
$user = wp_get_current_user();
echo ‘Welcome back <strong>’.$user->display_name.‘</strong> !’;
} else { ?>
Please <strong><?php wp_loginout(); ?></strong>
or <a href="<?php echo get_option(’home’); ?>/wp-login.php?action=register"> <strong>Register</strong></a>
<?php } ?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment