Skip to content

Instantly share code, notes, and snippets.

@leanda
leanda / WP_default_from_address.php
Created October 10, 2012 12:21
WordPress Default From Address (Paste into functions.php)
add_filter('wp_mail_from', 'new_mail_from');
add_filter('wp_mail_from_name', 'new_mail_from_name');
function new_mail_from($old) {
return '[email protected]';
}
function new_mail_from_name($old) {
return 'Your Blog Name';
}
@leanda
leanda / wordpress_css_comment.css
Created October 11, 2012 09:30
WordPress: style sheet comment block
/*!
Theme Name: Twenty Ten
Theme URI: http://wordpress.org/
Description: The 2010 default theme for WordPress.
Author: wordpressdotorg
Author URI: http://wordpress.org/
Version: 1.0
Tags: black, blue, white, two-columns, fixed-width, custom-header, custom-background, threaded-comments, sticky-post, translation-ready, microformats, rtl-language-support, editor-style, custom-menu (optional)
License:
@leanda
leanda / excerpt_tinymce.php
Created October 21, 2012 09:45
WordPress: add tinymce editor to the wordpress excerpt field
function tinymce_excerpt_js(){ ?>
<script type="text/javascript">
jQuery(document).ready( tinymce_excerpt );
function tinymce_excerpt() {
jQuery("#excerpt").addClass("mceEditor");
tinyMCE.execCommand("mceAddControl", false, "excerpt");
tinyMCE.onAddEditor.add(function(mgr,ed) {
if(ed.id=="excerpt"){
ed.settings.theme_advanced_buttons2 ="";
ed.settings.theme_advanced_buttons1 = "bold,italic,underline,seperator,justifyleft,justifycenter,justifyright,separator,link,unlink,seperator,pastetext,pasteword,removeformat,seperator,undo,redo,seperator,spellchecker,";
@leanda
leanda / wp_format_test.txt
Created November 20, 2012 14:20
WordPress: Format Test
<h1>Heading 1</h1>
Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, <a href="http://www.leandaryan.com">ut fermentum massa</a> justo sit amet risus. Aenean eu leo quam. <strong>Pellentesque ornare sem lacinia</strong> quam venenatis vestibulum.
<h2>Heading 2</h2>
Aenean lacinia <em>bibendum nulla sed consectetur</em>. Praesent commodo cursus magna, <del>vel scelerisque nisl consectetur</del> et.
<h3>Heading 3</h3>
Fusce dapibus, <em><strong>tellus ac cursus commodo, tortor mauris condimentum</strong></em> nibh, ut fermentum massa justo sit amet risus. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.
<h4>Heading 4</h4>
Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.
<ol>
<li>List Item</li>
@leanda
leanda / gist:4124060
Created November 21, 2012 09:56
WordPress: Replace parentheses from Category Counts
<?php
$variable = wp_list_categories('echo=0&show_count=1&include=1,2,3,4,5&title_li=');
$variable = str_replace('(', '<sup>', $variable);
$variable = str_replace(')', '</sup>', $variable);
echo $variable;
?>
@leanda
leanda / gist:4474336
Last active December 10, 2015 18:28
WordPress: Checking if a Widget has Been Activated
<?php
if ( is_active_widget( 'widget_name' ) ) {
echo '<h3>Heading</h3>';
}
?>
@leanda
leanda / cats-two-columns.php
Created February 20, 2013 14:16
WordPress: Categories, Two Columns
<?php
$cats = explode("<br />",wp_list_categories('title_li=&echo=0&depth=1&style=none'));
$cat_n = count($cats) - 1;
for ($i=0;$i<$cat_n;$i++):
if ($i<$cat_n/2):
$cat_left = $cat_left.'<li>'.$cats[$i].'</li>';
elseif ($i>=$cat_n/2):
$cat_right = $cat_right.'<li>'.$cats[$i].'</li>';
endif;
endfor;
@leanda
leanda / custom-logo.php
Created February 21, 2013 11:00
WordPress: Custom Logo Login
/*--- Custom Login Image ---*/
function my_custom_login_logo() {
echo '<style type="text/css">
h1 a {
background-image:url('.get_bloginfo('template_directory').'/images/login_logo.png) !important;
}
</style>';
}
@leanda
leanda / catch-image.php
Created February 21, 2013 11:11
WordPress: Catch first image from post
/*--- Catch the first image function use <?php echo catch_that_image() ?> ---*/
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
@leanda
leanda / remove-caption-style.php
Created February 21, 2013 15:58
WordPress: Remove inline styling of captions, helpful for responsive themes.
add_shortcode('wp_caption', 'fixed_img_caption_shortcode');
add_shortcode('caption', 'fixed_img_caption_shortcode');
function fixed_img_caption_shortcode($attr, $content = null) {
// Allow plugins/themes to override the default caption template.
$output = apply_filters('img_caption_shortcode', '', $attr, $content);
if ( $output != '' ) return $output;
extract(shortcode_atts(array(
'id'=> '',
'align' => 'alignnone',
'width' => '',