Add button to WordPress editor ~ TinyMCE
Don’t know why I’ve never done this before, but it’s quite simple. And makes it easier for users to add items in the visual editor, instead of [*gasp*] the text editor.
function enable_more_buttons($buttons) { $buttons[] = 'hr'; // Repeat with any other buttons you want to add, e.g. // $buttons[] = 'fontselect'; // $buttons[] = 'sup'; return $buttons; } add_filter("mce_buttons", "enable_more_buttons");
For more info here’s the article at WordPress Codex.
Published on April 29, 2013Custom Excerpt Lengths in WordPress
Sometimes shortened content just needs to be even shorter.
So, when you need that post/page content for a content slider or the like, give this little bit of code a go:
function my_excerpt($limit) { $excerpt = explode(' ', get_the_excerpt(), $limit); if (count($excerpt)>=$limit) { array_pop($excerpt); $excerpt = implode(" ",$excerpt).'...'; } else { $excerpt = implode(" ",$excerpt); } $excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt); return $excerpt; } function my_content($limit) { $content = explode(' ', get_the_content(), $limit); if (count($content)>=$limit) { array_pop($content); $content = implode(" ",$content).'...'; } else { $content = implode(" ",$content); } $content = preg_replace('/\[.+\]/','', $content); $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); return $content; }
Code thanks to a poster at Stack Overflow.
Published on February 22, 2013Normalize container height by row with javascript
I’ve been using a few methods to normalize container heights with javascript, but this one does that on a row-by-row basis. Since RWD is all the rage, this seems a pretty nifty solution. Here’s the code:
var currentTallest = 0, currentRowStart = 0, rowDivs = new Array(), $el, topPosition = 0; $('.blocks').each(function() { $el = $(this); topPostion = $el.position().top; if (currentRowStart != topPostion) { // we just came to a new row. Set all the heights on the completed row for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) { rowDivs[currentDiv].height(currentTallest); } // set the variables for the new row rowDivs.length = 0; // empty the array currentRowStart = topPostion; currentTallest = $el.height(); rowDivs.push($el); } else { // another div on the current row. Add it to the list and check if it's taller rowDivs.push($el); currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest); } // do the last row for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) { rowDivs[currentDiv].height(currentTallest); } });
$('.blocks')
would be changed to use whatever CSS selector you need to equalize.
Thanks CHRIS COYIER
Published on January 23, 2013WordPress String Replace
I’ve been working on a site for a fancy client and they need to maintain their brand identity at all costs. So, that means even though their name contains a hyphen, it must NEVER break onto a new line which would split the name.
Tried a couple different methods: javascript and php. Since the site is built in WP I went with the php method. Here it is:
function dont_break_lc($content){ return str_replace('fancy-name', '<span style="white-space:nowrap">fancy-name</span>', $content); } add_filter('the_title', 'dont_break_lc'); add_filter('the_content', 'dont_break_lc'); add_filter('the_excerpt', 'dont_break_lc');
There are still a couple of problems with this solution. str_replace
is case dependent so I have to repeat the function for Mixed Case and UPPER CASE occurrences so it shows up as dont_break_Mc()
and dont_break_UC()
in my functions.php file.
I should add that I settled on the CSS nowrap solution so the site validated. <nobr>
is more elegant and works without CSS, but c’mon , who disables CSS these days?
Contact Form 7 Field Data
So, here it is so I don’t have to type it out again. Contact Form 7 common field data for selects that have a lot of options.
State:
[select cf_state include_blank "AL" "AK" "AZ" "AR" "CA" "CO" "CT" "DE" "FL" "GA" "HI" "ID" "IL" "IN" "IA" "KS" "KY" "LA" "ME" "MD" "MA" "MI" "MN" "MS" "MO" "MT" "NE" "NV" "NH" "NJ" "NM" "NY" "NC" "ND" "OH" "OK" "OR" "PA" "RI" "SC" "SD" "TN" "TX" "UT" "VT" "VA" "WA" "WV" "WI" "WY"]
Country:
[select cf_country include_blank "United States" "Afghanistan" "Albania" "Algeria" "American Samoa" "Andorra" "Angola" "Anguilla" "Antarctica" "Antigua and Barbuda" "Argentina" "Armenia" "Arctic Ocean" "Aruba" "Ashmore and Cartier Islands" "Atlantic Ocean" "Australia" "Austria" "Azerbaijan" "Bahamas" "Bahrain" "Baker Island" "Bangladesh" "Barbados" "Bassas da India" "Belarus" "Belgium" "Belize" "Benin" "Bermuda" "Bhutan" "Bolivia" "Bosnia and Herzegovina" "Botswana" "Bouvet Island" "Brazil" "British Virgin Islands" "Brunei" "Bulgaria" "Burkina Faso" "Burundi" "Cambodia" "Cameroon" "Canada" "Cape Verde" "Cayman Islands" "Central African Republic" "Chad" "Chile" "China" "Christmas Island" "Clipperton Island" "Cocos Islands" "Colombia" "Comoros" "Cook Islands" "Coral Sea Islands" "Costa Rica" "Cote d'Ivoire" "Croatia" "Cuba" "Cyprus" "Czech Republic" "Denmark" "Democratic Republic of the Congo" "Djibouti" "Dominica" "Dominican Republic" "East Timor" "Ecuador" "Egypt" "El Salvador" "Equatorial Guinea" "Eritrea" "Estonia" "Ethiopia" "Europa Island" "Falkland Islands (Islas Malvinas)" "Faroe Islands" "Fiji" "Finland" "France" "French Guiana" "French Polynesia" "French Southern and Antarctic Lands" "Gabon" "Gambia" "Gaza Strip" "Georgia" "Germany" "Ghana" "Gibraltar" "Glorioso Islands" "Greece" "Greenland" "Grenada" "Guadeloupe" "Guam" "Guatemala" "Guernsey" "Guinea" "Guinea-Bissau" "Guyana" "Haiti" "Heard Island and McDonald Islands" "Honduras" "Hong Kong" "Howland Island" "Hungary" "Iceland" "India" "Indian Ocean" "Indonesia" "Iran" "Iraq" "Ireland" "Isle of Man" "Israel" "Italy" "Jamaica" "Jan Mayen" "Japan" "Jarvis Island" "Jersey" "Johnston Atoll" "Jordan" "Juan de Nova Island" "Kazakhstan" "Kenya" "Kingman Reef" "Kiribati" "Kerguelen Archipelago" "Kosovo" "Kuwait" "Kyrgyzstan" "Laos" "Latvia" "Lebanon" "Lesotho" "Liberia" "Libya" "Liechtenstein" "Lithuania" "Luxembourg" "Macau" "Macedonia" "Madagascar" "Malawi" "Malaysia" "Maldives" "Mali" "Malta" "Marshall Islands" "Martinique" "Mauritania" "Mauritius" "Mayotte" "Mexico" "Micronesia" "Midway Islands" "Moldova" "Monaco" "Mongolia" "Montenegro" "Montserrat" "Morocco" "Mozambique" "Myanmar" "Namibia" "Nauru" "Navassa Island" "Nepal" "Netherlands" "Netherlands Antilles" "New Caledonia" "New Zealand" "Nicaragua" "Niger" "Nigeria" "Niue" "Norfolk Island" "North Korea" "North Sea" "Northern Mariana Islands" "Norway" "Oman" "Pacific Ocean" "Pakistan" "Palau" "Palmyra Atoll" "Panama" "Papua New Guinea" "Paracel Islands" "Paraguay" "Peru" "Philippines" "Pitcairn Islands" "Poland" "Portugal" "Puerto Rico" "Qatar" "Reunion" "Republic of the Congo" "Romania" "Russia" "Rwanda" "Saint Helena" "Saint Kitts and Nevis" "Saint Lucia" "Saint Pierre and Miquelon" "Saint Vincent and the Grenadines" "Samoa" "San Marino" "Sao Tome and Principe" "Saudi Arabia" "Senegal" "Serbia" "Seychelles" "Sierra Leone" "Singapore" "Slovakia" "Slovenia" "Solomon Islands" "Somalia" "South Africa" "South Georgia and the South Sandwich Islands" "South Korea" "Spain" "Spratly Islands" "Sri Lanka" "Sudan" "Suriname" "Svalbard" "Swaziland" "Sweden" "Switzerland" "Syria" "Taiwan" "Tajikistan" "Tanzania" "Thailand" "Togo" "Tokelau" "Tonga" "Trinidad and Tobago" "Tromelin Island" "Tunisia" "Turkey" "Turkmenistan" "Turks and Caicos Islands" "Tuvalu" "Uganda" "Ukraine" "United Arab Emirates" "United Kingdom" "Uruguay" "Uzbekistan" "Vanuatu" "Venezuela" "Viet Nam" "Virgin Islands" "Wake Island" "Wallis and Futuna" "West Bank" "Western Sahara" "Yemen" "Yugoslavia" "Zambia" "Zimbabwe"]
2012 Top Listens
Straight from my LastFM profile:
- Seapony
- King Tuff
- Black Market Karma
- Allah-Las
- Woods
- Tanlines
- Grimes
- Digital Leather
- Lower Dens
- Django Django
- The Duke Spirit
- Modest Mouse
- DIIV
- Tennis
- Frankie Rose
- Hospitality
- Love Inks
- Devin
- Nick Waterhouse
- Alt-J
- Menomena
- La Sera
- Paws
- The Sea and Cake
- Poliça
- Passion Pit
- Girls
- Red Fang
- Colleen Green
- Chase & Status
- Built to Spill
- Peaking Lights
- Andrew Bird
- Jeans Wilder
- Deep Time
- Opossom
- Willie Nelson
- Craft Spells
- Bahamas
- Totally Enormous Extinct Dinosaurs
- Bleeding Knees Club
- Milk Maid
- Crocodiles
- Moon Duo
- Torche
- Liquor Store
- Sleepy Sun
- JJ
- Howler
- Agent Ribbons
Browser Screen Resolution Market Share
Published on September 21, 2012
Having your site hacked sucks!
I had noticed that some sites I admin were showing blocks of nefarious code, if you’ve never been hacked it kinda looks something like this:
echo eval(base64_decode("BAD CODES HERE"));
I was then lucky enough to dig through the sites and find all instances of the bad/offensive code. Here are some Linux CLI commands to make that much easier:
grep "((eval.*(base64_decode|gzinflate))|r57|c99|sh(3(ll|11)))" . -roE --include=*.php*
Run this at your hosting root and it will give you some standard output for each file that has the bad code. Update all those files and lock the sites down, that is, make them read only so the bad codes can no longer spread.
Now to find out where they got in. Here’s one to help read through the logs:
grep --color=auto -n 'POST' ~/PATH/TO/HTTP/LOGS/* > ~/post_hack.txt
Update the command with the path to your HTTP logs, but be sure to leave the asterisk, since you will want to search all log files. That one will print standard output into the post_hack.txt file so you can do some light reading to figure out where the intrusion originated. Most likely there will be some gibberish PHP file making a bunch of POST requests.
Good luck.
Published on September 18, 2012CSS3 I barely know you…border images are awesome!
Working on a site for a client and the design requires lots of hand drawn looking flourishes in the UI. The one that has been vexing me in laying out the markup is that of the input form field border. Enter the css3 property border-image
See here for reference.
I have an image that is the height of the input elements and is the width of the max-width of the container it could appear in. So I just add this to my css file:
input[type=text] { -moz-border-image:url("bg-input.png") 2 2 2 round; -webkit-border-image:url("bg-input.png") 2 2 2 round; -o-border-image:url("bg-input.png") 2 2 2 round; border-image:url("bg-input.png") 2 2 2 round; }
Here’s the image:
Google Maps IFRAME tricks
When doing sites I usually use the Google Maps IFRAME to drop a map onto the contact page or whatnot. I know the JS API is way cooler, but time is of the essence more often than never. So, anyway…The problem with using the copy-and-paste code from the Google Maps website is that it zooms to center on the map point, often leaving the balloon with the address outside the bounds of the iframe. What is more desirable is to have the map point and balloon zoom to fit. Well, here’s my solution to make that happen.
<iframe width="100%" height="400" frameborder="0" scrolling="yes" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&iwd=1&iwloc=addr&source=s_q&hl=en&geocode=&t=m&q=The+White+House&sll=&sspn=&ie=UTF8&hq=&hnear=1600+Pennsylvania+Ave,+Washington+DC&ll=&spn=0.035898,0.055189&z=16&output=embed"></iframe>