Remove URL from string PHP

by in 0

f I have a string that contains a url (for examples sake, we'll call it $url) such as;

$url = "Here is a funny site http://www.tunyurl.com/34934";
How do i remove the URL from the string? Difficulty is, urls might also show up without the http://, such as ;
$url = "Here is another funny site www.tinyurl.com/55555";

There is no HTML present. How would i start a search if http or www exists, then remove the text/numbers/symbols until the first space?


##########

function containsTLD($string) {
  preg_match(
    "/(AC($|\/)|\.AD($|\/)|\.AE($|\/)|\.AERO($|\/)|\.AF($|\/)|\.AG($|\/)|\.AI($|\/)|\.AL($|\/)|\.AM($|\/)|\.AN($|\/)|\.AO($|\/)|\.AQ($|\/)|\.AR($|\/)|\.ARPA($|\/)|\.AS($|\/)|\.ASIA($|\/)|\.AT($|\/)|\.AU($|\/)|\.AW($|\/)|\.AX($|\/)|\.AZ($|\/)|\.BA($|\/)|\.BB($|\/)|\.BD($|\/)|\.BE($|\/)|\.BF($|\/)|\.BG($|\/)|\.BH($|\/)|\.BI($|\/)|\.BIZ($|\/)|\.BJ($|\/)|\.BM($|\/)|\.BN($|\/)|\.BO($|\/)|\.BR($|\/)|\.BS($|\/)|\.BT($|\/)|\.BV($|\/)|\.BW($|\/)|\.BY($|\/)|\.BZ($|\/)|\.CA($|\/)|\.CAT($|\/)|\.CC($|\/)|\.CD($|\/)|\.CF($|\/)|\.CG($|\/)|\.CH($|\/)|\.CI($|\/)|\.CK($|\/)|\.CL($|\/)|\.CM($|\/)|\.CN($|\/)|\.CO($|\/)|\.COM($|\/)|\.COOP($|\/)|\.CR($|\/)|\.CU($|\/)|\.CV($|\/)|\.CX($|\/)|\.CY($|\/)|\.CZ($|\/)|\.DE($|\/)|\.DJ($|\/)|\.DK($|\/)|\.DM($|\/)|\.DO($|\/)|\.DZ($|\/)|\.EC($|\/)|\.EDU($|\/)|\.EE($|\/)|\.EG($|\/)|\.ER($|\/)|\.ES($|\/)|\.ET($|\/)|\.EU($|\/)|\.FI($|\/)|\.FJ($|\/)|\.FK($|\/)|\.FM($|\/)|\.FO($|\/)|\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($|\/)|\.XN--ZCKZAH($|\/)|\.YE($|\/)|\.YT($|\/)|\.YU($|\/)|\.ZA($|\/)|\.ZM($|\/)|\.ZW)/i",
    $string,
    $M);
  $has_tld = (count($M) > 0) ? true : false;
  return $has_tld;
}

function cleaner($url) {
  $U = explode(' ',$url);

  $W =array();
  foreach ($U as $k => $u) {
    if (stristr($u,".")) { //only preg_match if there is a dot    
      if (containsTLD($u) === true) {
      unset($U[$k]);
      return cleaner( implode(' ',$U));
    }      
    }
  }
  return implode(' ',$U);
}


$url = "Here is another funny site badurl.badone somesite.ca/worse.jpg but this badsite.com www.tinyurl.com/55555 and http://www.tinyurl.com/55555 and img.hostingsite.com/badpic.jpg";
echo "Cleaned: " . cleaner($url);
returns:

Cleaned: Here is another funny site badurl.badone but this and and

Free Music player for website, blogger

by in , 0

Ketnooi Music release Free new Music player for Webmasters.
You can embed K-Player to your blog, blogspot easily.
Demo see this blog
Features:
- Free music/Video for your vistors
- Easy to embed
- Light speed
- Integrate with any website, blog.
- Music is not breakable even if vistor go to new page


Just go to Video.Ketnooi.com, then create your own playlist, Save it, then get embed Code
 
Have fun!

javascript replace only first instance .replace?

by in 0

I have this
 var date = $('#Date').val();
this get the value in the textbox what would look like this
12/31/2009
Now I do this on it
var id = 'c_' + date.replace("/", '');
and the result is
c_1231/2009
It misses the last '/' I don't understand why though.

Read more »

BEST 200+ Free Responsive HTML5 templates

by in , , 0

free Collection of responsive html5 css3 templates are well-designed layout template for any kind of business, company, personal, blog, website with new html5 and css3 features! (updated 2014)

All free premium responsive Using HTML5 and CSS3 features are popular among web designers nowadays. HTML5 also provide great features to create animation on web instead of flash animation. Websites developed in HTML5 animation will not require adobe flash support on your web browser anymore, provided that your browser supports HTML5. There are more kind of html5 css3 website templates such education templates, hotel templates and more.

Free HTML5 Theme for Interior Site

Free HTML5 Theme for Business Site

Read more »

Simple Responsive Drop Down Menu jQuery CSS3

by in , 0

A beauty drop down responsive menu that shows its sub menus with icon symbol using open symbol fonts that allowing you to add more icons as you want. With my previous tutorial, i also show how to create Creating 3-Level Responsive Drop Down Navigation Menu with jQuery and CSS3 as well.
demo-drop-down-menu



Today we would like to show an experimental drop-down menu with jquery and css3 using beautiful symbol fonts. The main idea is to help you to save time for creating menus for website, it have a lot of content and sub-levels. Some sub-level in this menu will be shown in its context and icons. The menu is best use in professional web design that it can be used easily in a responsive layout.
This Responsive Drop Down Navigation Menu using plugin such as:

Read more »

30 Best HTML5 3D Effect examples

by in , 0

In this article you will see that there are some amazing HTML5 and CSS3 3D graphics examples with demo link. Usually, HTML5 goes hand in hand with CSS3 to create the professional web experiences. In fact, websites developed in HTML5 animation will not require adobe flash support on your Web browser anymore, provided that your browser supports HTML5.
Many people believe that HTML5 new advanced technology to create professional website and animation templates on web online in stead of flash. HTML5 is a lightweight, powerful and easy to use platform such as games, 3D animation, 3D graphics by using HTML5 canvas, CSS3 and JavaScript. In fact, HTML5 and CSS3 represents the future of mobile browsing and that’s because of it’s comprehensive and lightweight abilities.
CSS 3D transforms are smooth, hardware accelerated and simple to implement, with browsers taking on what would be very difficult perspective calculations.
Recommendation: For best results, please use a browser that supports HTML5 and CSS3 such as Google Chrome, Latest Versions of Firefox or Opera

The World Wonders 3D globe

The World Wonders 3D globe

3D CSS Text

3D CSS Text

Read more »

Change Default Text Selection Color by CSS

by in , 0

Whilst this CSS3 declaration might not be crucial to your project or design and yes it is not supported by all browsers, but it is a fantastic effect that really takes your design one step further.
Currently FireFox, Safari, Chrome and Opera support the text section attribute, and the browsers that don’t support it simply ignore the code so nothing will break, so it doesn’t really matter.
We have setup a demo which you can test out further down the page; we have used the Design Juices colours in the example.



Read more »

Sticky notes CSS3

by in , 0


I’ve been working on a pretty cool wall-mounted status board as one of my projects at Fog Creek. It’s a webapp that runs on a vertically mounted LCD screen in our office. It displays a bunch of interesting information like tech support calls, staff vacations, tweets about FogBugz, and more.

I’ve been incrementally adding features and improving the UI whenever I have spare cycles. The other night, I decided to redesign the Kanban board widget, which is a list of the top N things that the customer team needs from engineering. I decided to go with a sticky note UI that mimics a real-life Kanban board, which typically consists of a giant white board filled with a bunch of sticky notes.

My initial design used the classic yellow sticky notes, which I thought looked pretty neat. I showed my co-worker Rich who suggested that we make the notes look like the FogBugz and Kiln notepads that are laying around the office. Awesome idea! Way better.



Read more »

Rotating Image Slideshow Jquery

by in , 0

Today we are going to use jQuery and CSS3 rotations, along with the jQuery rotate plugin, to create a beautiful slideshow. You can use it to spice up your web sites, product pages and other projects with some CSS3 magic.



Read more »

Multi-Step Signup Form With CSS3 and jQuery

by in , , 0

In this tutorial we will see how to create a simple multi-step signup form using CSS3 and jQuery. To spice up things a bit, we will include progress bar with the form, so the users will be able to see the percentage of form completion.

You can take a look at the working demo if you click on the image below:

Create A Multi-Step Signup Form With CSS3 and jQuery DEMO
We will create four steps in our form:
1. username and password fields
2. first and last name and email address
3. age, gender and country
4. summary

Download Code

Related Posts sidebar with jQuery and CSS3 | Brighten up by Css series

by in 0

The other day we were wondering how we could show our visitors more of our works. It’s normal that in a blog older posts get forgotten and even if something might still be very interesting and relevant, it get’s lost under the pile of new stuff. So we decided to create something like a little widget that can be used to show related posts in any page. The main idea is to show a fixed list at the right side of the screen with some thumbnails sticking out. When the user hovers over the items, they slide out, revealing the title and two links, one for the related article itself and one for the demo. Additionally, we will have a shuffle button under the list. When pressed, the list gets randomly refreshed with related posts.
Before we use this, we of course, want to share it with you :)



Read more »

PHP Detect URL Protocol - http vs https

by in 0

I've written a little function to establish the current site url protocol but I don't have SSL and don't know how to test if it works under https. Can you tell me if this is correct?

function siteURL()
{
    $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
    $domainName = $_SERVER['HTTP_HOST'].'/';
    return $protocol.$domainName;
}
define( 'SITE_URL', siteURL() );
Is it necessary to do it like above or can I just do it like?:
function siteURL()
{
    $protocol = 'http://';
    $domainName = $_SERVER['HTTP_HOST'].'/'
    return $protocol.$domainName;
}
define( 'SITE_URL', siteURL() );
Under SSL, doesn't the server automatically convert the url to https even if the anchor tag url is using http? Is it necessary to check for the protocol?

Thank you!



Read more »

Create a nice CSS3 Progress bar without any images | Brighten up by Css series

by in , , 0

As I’ve shown you in some of my recent posts, the new features introduced in CSS3 allows developers to create stunning visual effects. Today, let’s create a fancy progress bar using CSS3 and jQuery, but no Flash or even images.

Please note: The original CSS3 progress bar shown in this tutorial has been created by Ivan Vanderbyl, which hereby gave me the right to reproduce and document his work.
The following tutorial and the demo works best on Chrome and Safari, correctly on Firefox and very badly in Internet Explorer (eh…I’m sure you hadn’t guessed that).

The Demo

Read more »

Draw a Vibrant Poster/Banner by CSS | Brighten up by Css series

by in , 0

CSS has come a long way in recent years, and with new browser support for a hand full of CSS3 properties we can begin to replicate design styles directly in the browser that beforehand were recently only possible in our design applications. Follow this walkthrough of the making of Circlicious, a vibrant and abstract digital poster design made purely of HTML and CSS.


View the CSS poster demo
The Circlicious poster art makes use of plenty of circular geometric shapes and features lots of transparency to add multiple levels to the design, giving the design that bright and crisp feel of typical vector artworks. Being a design that makes use of CSS3 properties, it’s only suited to the modern browsers of Firefox, Safari and Chrome.

Firefox, Safari & Chrome = Win. Opera… Meh. Internet Explorer… I wouldn’t even bother.

Read more »

Mini Navigation Menu | Brighten up by Css series

by in , 0

As you have probably heard by now, CSS3 animations are a powerful tool, which enables you to create animations which run without the need of applying additional scripting to the page. What is even better, in the next generation of browsers we will have even more powerful tools, including 3D transformations (already present in Safari).
But what difference does it make for us today? At the moment only three browsers give you the ability to animate CSS properties – Chrome, Safari and Opera, which together take up only a small part of the browser market. Firefox is expected to soon join the club, and with the impending release of IE9, it suddenly makes sense to start leveraging this technique.

So today we are making something practical – a simple CSS3 animated navigation menu, which degrades gracefully in older browsers and is future-proofed to work with the next generation of browsers.



DEMO:

Read more »

Nice Full page Menu | Brighten up by Css Series

by in , 0

In today’s tutorial we will create a full page cufonized menu that has two nice features: when hovering over the menu items we will move a hover-state item that adapts to the width of the current item, and we will slide out a description bar from the left side of the page, reaching towards the current menu item.
We will use jQuery for the effect and some CSS3 properties for the style. We are not going to use any images.



DEMO:

Read more »

Change highlight color with JQuery

by in 0

jQuery's highlight method will highlight any div with a yellow background.
How do I specify what color to use instead of yellow for highlight?

Answer:


$(this).effect("highlight", {color: 'blue'}, 3000);

HP Pavilion a255c drivers

by in , 0

Direct Download Drivers HP Pavilion a255c drivers


Index
Application
BIOS
Diagnostics
Firmware
Keyboard and Input Devices
Modem
Network
OS
Software
Sound Card
Update
Utility
Video Card

Category: Application
OS: Windows XP
Version: 1.05.002g
Date: 07 Jul 2003
Filesize: 1.95 MB
Download file

Category: Application
OS: Windows XP
Version: 1.4.2_03
Date: 11 Dec 2003
Filesize: 12.27 MB
Download file

Read more »

HP Pavilion a250y drivers

by in , 0

Direct Download Drivers HP Pavilion a250y drivers


Index
Application
BIOS
Diagnostics
Keyboard and Input Devices
Modem
Network
OS
Software
Utility

Category: Application
OS: Windows XP
Version: 1.4.2_03
Date: 11 Dec 2003
Filesize: 12.27 MB
Download file

Read more »

HP Pavilion a250n drivers

by in , 0

Direct Download Drivers HP Pavilion a250n drivers


Index
Application
BIOS
Diagnostics
Firmware
Keyboard and Input Devices
Modem
Network
OS
Software
Sound Card
Update
Utility
Video Card

Category: Application
OS: Windows XP
Version: 1.05.002g
Date: 07 Jul 2003
Filesize: 1.95 MB
Download file

Category: Application
OS: Windows XP
Version: 1.4.2_03
Date: 11 Dec 2003
Filesize: 12.27 MB
Download file

Category: Application
OS: Windows XP
Version: 5-27-2003
Date: 27 May 2003
Filesize: 0.93 MB
Download file

Read more »

HP Pavilion a250e drivers

by in , 0

Direct Download Drivers HP Pavilion a250e drivers


Index
Application
BIOS
Diagnostics
Keyboard and Input Devices
Modem
OS
Software
Utility

Category: Application
OS: Windows XP
Version: 1.4.2_03
Date: 11 Dec 2003
Filesize: 12.27 MB
Download file

Read more »

HP Pavilion a248.fr drivers

by in , 0

Direct Download Drivers HP Pavilion a248.fr drivers


Index
Utility

Category: Utility
OS: Windows XP
Version: N/A
Date: 10 Aug 2004
Filesize: 0.94 MB
Download file

Category: Utility
OS: Windows XP
Version: N/A
Date: 10 Aug 2004
Filesize: 2.23 MB
Download file

Category: Utility
OS: Windows XP
Version: N/A
Date: 11 Aug 2004
Filesize: 14.98 MB
Download file

Category: Utility
OS: Windows XP
Version: N/A
Date: 11 Aug 2004
Filesize: 37.14 MB
Download file

Category: Utility
OS: Windows XP
Version: N/A
Date: 11 Aug 2004
Filesize: 2.74 MB
Download file

Category: Utility
OS: Windows XP
Version: N/A
Date: 11 Aug 2004
Filesize: 2.75 MB
Download file

Category: Utility
OS: Windows XP
Version: N/A
Date: 11 Aug 2004
Filesize: 0.85 MB
Download file

Category: Utility
OS: Windows XP
Version: N/A
Date: 11 Aug 2004
Filesize: 0.86 MB
Download file

Read more »

HP Pavilion a245c drivers

by in , 0

Direct Download Drivers HP Pavilion a245c drivers


Index
Application
BIOS
Diagnostics
Firmware
Keyboard and Input Devices
Modem
OS
Software
Sound Card
Update
Utility
Video Card

Category: Application
OS: Windows XP
Version: 1.05.002g
Date: 07 Jul 2003
Filesize: 1.95 MB
Download file

Category: Application
OS: Windows XP
Version: 1.4.2_03
Date: 11 Dec 2003
Filesize: 12.27 MB
Download file

Read more »

HP Pavilion a235.uk drivers

by in , 0

Direct Download Drivers HP Pavilion a235.uk drivers


Index
Application
Diagnostics
Firmware
Keyboard and Input Devices
OS
Software
Sound Card
Update
Utility
Video Card

Category: Application
OS: Windows XP
Version: 1.4.2_03
Date: 11 Dec 2003
Filesize: 12.27 MB
Download file

Read more »

HP Pavilion a230n drivers

by in , 0

Direct Download Drivers HP Pavilion a230n drivers


Index
Application
BIOS
Diagnostics
Firmware
Keyboard and Input Devices
Modem
OS
Software
Sound Card
Update
Utility
Video Card

Category: Application
OS: Windows XP
Version: 1.05.002g
Date: 07 Jul 2003
Filesize: 1.95 MB
Download file

Category: Application
OS: Windows XP
Version: 1.4.2_03
Date: 11 Dec 2003
Filesize: 12.27 MB
Download file

Category: Application
OS: Windows XP
Version: 5-27-2003
Date: 27 May 2003
Filesize: 0.93 MB
Download file

Read more »

HP Pavilion a220n drivers

by in , 0

Direct Download Drivers HP Pavilion a220n drivers


Index
Application
BIOS
Diagnostics
Firmware
Keyboard and Input Devices
Modem
OS
Software
Sound Card
Update
Utility
Video Card

Category: Application
OS: Windows XP
Version: 1.05.002g
Date: 07 Jul 2003
Filesize: 1.95 MB
Download file

Category: Application
OS: Windows XP
Version: 1.4.2_03
Date: 11 Dec 2003
Filesize: 12.27 MB
Download file

Read more »

HP Pavilion a220a drivers

by in , 0

Direct Download Drivers HP Pavilion a220a drivers


Index
Application
BIOS
Diagnostics
Firmware
Keyboard and Input Devices
Modem
OS
Software
Sound Card
Update
Utility

Category: Application
OS: Windows XP
Version: 1.05.002g
Date: 07 Jul 2003
Filesize: 1.95 MB
Download file

Category: Application
OS: Windows XP
Version: 1.4.2_03
Date: 11 Dec 2003
Filesize: 12.27 MB
Download file

Read more »

Adding a Meta Description to Blogspot

by in 0

 An important part of a good SEO is the implementation of meta tags, which are commonly located in the header of our website, that are being, in the same time, invisible to users visiting the site. Well, to be more succinct, these tags have only one purpose: to include information about the page such as author name, date, key word, description, title, among others.

However, here we will only mention one, which is the meta description in Blogger. This description will appear as a fragment in the search results and as a description when sharing on Google+, Facebook and other social networks. A clear and precise description increases the chances of getting more clicks or visits.

As we will work only on the Blogger platform, here I will leave a little guide to easily add a meta description.

Read more »

Random Posts Widget to Blogspot

by in 0

 The Random Posts widget or gadget for Blogger will show random posts you have added to your blog that due to the natural structure of blogs, could get lost deep in your archives, as most new users join and pick up from the moment they join, and they never bother going back to one of your good posts.

One of the easiest way to give a new life to your older posts is to display them in a random order in your sidebar. In this tutorial, I will share how you can add a random posts gadget in a Blogger blog.

The advantages of this widget is that is loading pretty fast and shows thumbnails of your posts and how many comments they have received, as well. So, let's begin adding it!


How to add Random Posts Widget to Blogger


Step 1. From your Blogger Dashboard, Go to Layout, click on Add a Gadget 

random posts widget, random blogger

Step 2. Add a new HTML/JavaScript Gadget
random posts blogger

Step 3. Paste the following code in the empy HTML box:
<style>
#random-posts img{float:left;margin-right:10px;
width:65px;height:50px;background-color: #F5F5F5;padding: 3px;}
ul#random-posts {list-style-type: none;}
</style>

<ul id='random-posts'>
<script type='text/javaScript'>
var rdp_numposts=5;
var rdp_snippet_length=150;
var rdp_info='yes';
var rdp_comment='Comments';
var rdp_disable='Comments Disabled';
var rdp_current=[];var rdp_total_posts=0;var rdp_current=new Array(rdp_numposts);function totalposts(json){rdp_total_posts=json.feed.openSearch$totalResults.$t}document.write('<script type=\"text/javascript\" src=\"/feeds/posts/default?alt=json-in-script&max-results=0&callback=totalposts\"><\/script>');function getvalue(){for(var i=0;i<rdp_numposts;i++){var found=false;var rndValue=get_random();for(var j=0;j<rdp_current.length;j++){if(rdp_current[j]==rndValue){found=true;break}};if(found){i--}else{rdp_current[i]=rndValue}}};function get_random(){var ranNum=1+Math.round(Math.random()*(rdp_total_posts-1));return ranNum};
</script>
<script type='text/javaScript'>
function random_posts(json){for(var i=0;i<rdp_numposts;i++){var entry=json.feed.entry[i];var rdp_posttitle=entry.title.$t;if('content'in entry){var rdp_get_snippet=entry.content.$t}else{if('summary'in entry){var rdp_get_snippet=entry.summary.$t}else{var rdp_get_snippet="";}};rdp_get_snippet=rdp_get_snippet.replace(/<[^>]*>/g,"");if(rdp_get_snippet.length<rdp_snippet_length){var rdp_snippet=rdp_get_snippet}else{rdp_get_snippet=rdp_get_snippet.substring(0,rdp_snippet_length);var space=rdp_get_snippet.lastIndexOf(" ");rdp_snippet=rdp_get_snippet.substring(0,space)+"&#133;";};for(var j=0;j<entry.link.length;j++){if('thr$total'in entry){var rdp_commentsNum=entry.thr$total.$t+' '+rdp_comment}else{rdp_commentsNum=rdp_disable};if(entry.link[j].rel=='alternate'){var rdp_posturl=entry.link[j].href;var rdp_postdate=entry.published.$t;if('media$thumbnail'in entry){var rdp_thumb=entry.media$thumbnail.url}else{rdp_thumb="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjBnpR5lDZhyphenhyphend91xdjFBXV_OacMyHD8fWf6XlwMtNxWmvjLr6vJ1uT4XUA6XB7k3C3FMXm92Z98v4UnnebSCaJ7uSnFLIau_oSrAfejeTTw-A1dKXt42sLv7MRG-o2-PPodGzNY_OzxMo8/s1600/no_thumb.png"}}};document.write('<li>');document.write('<img alt="'+rdp_posttitle+'" src="'+rdp_thumb+'"/>');document.write('<div><a href="'+rdp_posturl+'" rel="nofollow" title="'+rdp_snippet+'">'+rdp_posttitle+'</a></div>');if(rdp_info=='yes'){document.write('<span>'+rdp_postdate.substring(8,10)+'/'+rdp_postdate.substring(5,7)+'/'+rdp_postdate.substring(0,4)+' - '+rdp_commentsNum)+'</span>'}document.write('<div style="clear:both"></div></li>')}};getvalue();for(var i=0;i<rdp_numposts;i++){document.write('<script type=\"text/javascript\" src=\"/feeds/posts/default?alt=json-in-script&start-index='+rdp_current[i]+'&max-results=1&callback=random_posts\"><\/script>')};
</script>
</ul>
Replace 5 with the number of posts you want to be show.
For bigger thumbnails, change the pixels in red from width:65px;height:50px

Step 4. Press Save and you're done! Enjoy!

Download image with PHP CURL

by in 0

If you have allow_url_fopen set to true:

$url = 'http://example.com/image.php';
$img = '/my/folder/flower.gif';
file_put_contents($img, file_get_contents($url));


Else use cURL:


$ch = curl_init('http://example.com/image.php');
$fp = fopen('/my/folder/flower.gif', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);fclose($fp);




Source: Saving image from PHP URL using PHP


difference between jQuery .val() and .attr('value')?

by in 0

.val() works on all input type elements in a useful way, including <select>...even in the cases of <select multiple>, checkboxes, and radio buttons (in which .val() gets or sets an array of selected values not just a string).
So basically they serve different purposes, even though .attr('value') behaves the same in some situations, like textboxes. The preferred method is .val() to get consistent behavior everywhere.
Just for kicks, here's a lesser-known example for checkboxes that makes .val() handy:
<input name="mytest" type="checkbox" value="1">
<input name="mytest" type="checkbox" value="2">
<input name="mytest" type="checkbox" value="3">
<input name="mytest" type="checkbox" value="4">
You can do this:
$("input[name='mytest']").val([1, 2, 3]);
....which will check the first 3 boxes.


wordpress Year Shortcode

by in , 0

For the functions.php file:

function year_shortcode() {
  $year = date('Y');
  return $year;
}
add_shortcode('year', 'year_shortcode');

Usage

Use [year] in your posts.

wordpress Using Custom Fields

by in , 0

Dump out all custom fields as a list

<?php the_meta(); ?>

Display value of one specific custom field

<?php echo get_post_meta($post->ID, 'mood', true); ?>

"mood" would be ID value of custom field

Display multiple values of same custom field ID

<?php $songs = get_post_meta($post->ID, 'songs', false); ?>
<h3>This post inspired by:</h3>
<ul>
	<?php foreach($songs as $song) {
		echo '<li>'.$song.'</li>';
	} ?>
</ul>

Display custom field only if exists (logic)

<?php 
    $url = get_post_meta($post->ID, 'snippet-reference-URL', true); 

	if ($url) {
	    echo "<p><a href='$url'>Reference URL</a></p>";
	}
?>

Reference URL

wordpress Turn on WordPress Error Reporting

by in , 0

Comment out the top line there, and add the rest to your wp-config.php file to get more detailed error reporting from your WordPress site. Definitely don't do this live, do it for local development and testing.

// define('WP_DEBUG', false);

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors', 0);

wordpress Turn On More Buttons in the WordPress Visual Editor

by in , 0

These buttons (like one for adding an <hr> tag) aren't there by default in the WordPress visual editor, but you can turn them on pretty easily. This is code for your active theme's functions.php file, or make a functionality plugin.

function add_more_buttons($buttons) {
 $buttons[] = 'hr';
 $buttons[] = 'del';
 $buttons[] = 'sub';
 $buttons[] = 'sup';
 $buttons[] = 'fontselect';
 $buttons[] = 'fontsizeselect';
 $buttons[] = 'cleanup';
 $buttons[] = 'styleselect';
 return $buttons;
}
add_filter("mce_buttons_3", "add_more_buttons");

Reference URL

wordpress Spam Comments with Very Long URL’s

by in , 0

Super long URL's are a sure fire sign the comment is spammy. This will mark comments with URL's (as the author URL, not just in the text) longer than 50 characters as spam, otherwise leave their state the way it is.

<?php

  function rkv_url_spamcheck( $approved , $commentdata ) {
    return ( strlen( $commentdata['comment_author_url'] ) > 50 ) ? 'spam' : $approved;
  }

  add_filter( 'pre_comment_approved', 'rkv_url_spamcheck', 99, 2 );

?>

Reference URL

wordpress Shrink the Admin Bar / Expand on Hover

by in , 0

A mini plugin:

<?php
/*
 * Plugin Name: Mini Admin Bar
 * Plugin URI: http://www.netyou.co.il/
 * Description: Makes the admin bar a small button on the left and expands on hover.
 * Version: 1.0
 * Author: NetYou
 * Author URI: http://www.netyou.co.il/
 * License: MIT
 * Copyright: NetYou
*/
 
add_action('get_header', 'my_filter_head');
function my_filter_head() { remove_action('wp_head', '_admin_bar_bump_cb'); }
 
function my_admin_css() {
        if ( is_user_logged_in() ) {
        ?>
        <style type="text/css">
            #wpadminbar {
                width: 47px;
                min-width: auto;
                overflow: hidden;
                -webkit-transition: .4s width;
                -webkit-transition-delay: 1s;
                -moz-transition: .4s width;
                -moz-transition-delay: 1s;
                -o-transition: .4s width;
                -o-transition-delay: 1s;
                -ms-transition: .4s width;
                -ms-transition-delay: 1s;
                transition: .4s width;
                transition-delay: 1s;
            }
            
            #wpadminbar:hover {
                width: 100%;
                overflow: visible;
                -webkit-transition-delay: 0;
                -moz-transition-delay: 0;
                -o-transition-delay: 0;
                -ms-transition-delay: 0;
                transition-delay: 0;
            }
        </style>
        <?php }
}
add_action('wp_head', 'my_admin_css');

?>

Reference URL

wordpress Show Your Favorite Tweets with WordPress

by in , 0

Just replace the URL in the fetch_rss line below with the RSS feed to your Twitter favorites. In fact this will work with any RSS feed.

<?php
    include_once(ABSPATH . WPINC . '/feed.php');
    $rss = fetch_feed('http://twitter.com/favorites/793830.rss');
    $maxitems = $rss->get_item_quantity(3); 
    $rss_items = $rss->get_items(0, $maxitems);
?>

<ul>
    <?php if ($maxitems == 0) echo '<li>No items.</li>';
    else
    // Loop through each feed item and display each item as a hyperlink.
    foreach ( $rss_items as $item ) : ?>
    <li>
        <a href='<?php echo $item->get_permalink(); ?>'>
            <?php echo $item->get_title(); ?>
        </a>
    </li>
    <?php endforeach; ?>
</ul>

wordpress Shortcode in a Template

by in , 0

Shortcodes in WordPress are bits of text you can use in the content area to invoke some kind of function to accomplish certain tasks. For example, video embedding in WP 2.9+ uses the shortcode. You can write your own shortcodes, and plugins often offer their functionality via shortcodes as well.

But what if you want to use a shortcode from within a template instead of with the content of a Post/Page? You can invoke it with a special function:

<?php echo do_shortcode("[shortcode]"); ?>

wordpress Shortcode for Action Button

by in , 0

For functions.php

 /* Shortcode to display an action button. */
add_shortcode( 'action-button', 'action_button_shortcode' );
function action_button_shortcode( $atts ) {
       extract( shortcode_atts(
               array(
                       'color' => 'blue',
                       'title' => 'Title',
                       'subtitle' => 'Subtitle',
                       'url' => ''
               ),
               $atts
       ));
       return '<span class="action-button ' . $color . '-button"><a href="' . $url . '">' . $title . '<span class="subtitle">' . $subtitle . '</span>' . '</a></span>';
}

Usage in Post Editor

[action-button color="blue" title="Download Now" subtitle="Version 1.0.1 – Mac OSX" url="#"]

CSS for style.css file

Only includes "blue" styling, add others as you might.

.action-button a:link, .action-button a:visited {
       border-radius: 5px;
       display: inline-block;
       font: 700 16px Arial, Sans-Serif;
       margin: 0 10px 20px 0;
       -moz-border-radius: 5px;
       padding: 14px 18px;
       text-align: center;
       text-decoration: none;
       text-shadow: 0 1px 1px rgba(0,0,0,0.3);
       text-transform: uppercase;
       -webkit-border-radius: 5px;
}

.action-button .subtitle {
       display: block;
       font: 400 11px Arial, Sans-Serif;
       margin: 5px 0 0;
}

.blue-button a:link, .blue-button a:visited {
       background-color: #5E9CB9;
       background-image: -moz-linear-gradient(top, #5E9CB9, #4E7E95);
       background-image: -webkit-gradient(linear, left top, left bottom, from(#5E9CB9), to(#4E7E95));
       color: #FFF;
       filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#5E9CB9', EndColorStr='#4E7E95');
       -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorStr='#5E9CB9', EndColorStr='#4E7E95')";
}

.blue-button a:hover {
       background-color: #68A9C8;
       background-image: -moz-linear-gradient(top, #68A9C8, #598EA8);
       background-image: -webkit-gradient(linear, left top, left bottom, from(#68A9C8), to(#598EA8));
       color: #FFF;
       filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#68A9C8', EndColorStr='#598EA8');
       -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorStr='#68A9C8', EndColorStr='#598EA8')";
}

Sent in by Matt Adams.

wordpress Run Loop on Posts of Specific Category

by in , 0

<?php query_posts('cat=5'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
   <?php the_content(); ?>
<?php endwhile; endif; ?>

If you were to use this, for example, in a left sidebar which ran before the main loop on your page, remember to reset the query or it will upset that main loop.

<?php wp_reset_query(); ?>

wordpress Run a Loop Outside of WordPress

by in , 0

Include Basic WordPress Functions

<?php
  // Include WordPress
  define('WP_USE_THEMES', false);
  require('/server/path/to/your/wordpress/site/htdocs/blog/wp-blog-header.php');
  query_posts('showposts=1');
?>

Run Loop

<?php while (have_posts()): the_post(); ?>
   <h2><?php the_title(); ?></h2>
   <?php the_excerpt(); ?>
   <p><a href="<?php the_permalink(); ?>" class="red">Read more...</a></p>
<?php endwhile; ?>

This can be used on any PHP file even OUTSIDE your WordPress installation.

wordpress Reset Admin Password Through Database

by in , 0

You'll need to be able to run SQL on that database, like for example, through phpMyAdmin.

UPDATE `wp_users` SET `user_pass` = MD5( 'new_password_here' ) WHERE `wp_users`.`user_login` = "admin_username";

wordpress Reset Admin Password in Database

by in , 0

Forget your admin password and don't have access to the email account it's under? If you can get access to phpMyAdmin (or anything you can run mySQL commands), you can update it there.

UPDATE `wp_users` SET `user_pass` = MD5( 'new_password_here' ) WHERE `wp_users`.`user_login` = "admin_username";

Just replace new_password_here with the new password and admin_username with the real admin accounts usename.

wordpress Replace Excerpt Ellipsis with Permalink

by in , 0

This is useful if you would like to replace the ellipsis [...] from the excerpt with a permalink to the post.

functions.php addition:

function replace_excerpt($content) {
       return str_replace('[...]',
               '<div class="more-link"><a href="'. get_permalink() .'">Continue Reading</a></div>',
               $content
       );
}
add_filter('the_excerpt', 'replace_excerpt');

wordpress Remove WP Generator Meta Tag

by in , 0

It can be considered a security risk to make your wordpress version visible and public you should hide it.

Put in functions.php file in your theme:

remove_action('wp_head', 'wp_generator');

wordpress Remove Whitespace from Function Output

by in , 0

In WordPress, there are many functions which output things for you. For example, wp_list_pages() outputs a list of all your published pages. The HTML markup it spits out is pretty nicely formatted (meaning: has line breaks and indenting).

There are some circumstances where all that "whitespace" in the formatting is undesirable. Like 1) it's all the more characters to deliver and 2) closing "the gap" in older versions of IE.

If the function supports a way to return a string (rather than immediately echo it), you can use a regex to remove the space:

<?php
   echo preg_replace('/>\s+</m', '><', wp_list_pages('echo=0'));
?>

wordpress Remove the 28px Push Down from the Admin Bar

by in , 0

For your functions.php file:

  add_action('get_header', 'my_filter_head');

  function my_filter_head() {
    remove_action('wp_head', '_admin_bar_bump_cb');
  }

By default, if you are seeing the admin bar as a logged in WordPress user, CSS like this will be output in your head (output in the wp_head() function):

<style type="text/css" media="screen">
	html { margin-top: 28px !important; }
	* html body { margin-top: 28px !important; }
</style>

This is normally a good thing, as it doesn't cover parts of your site then with its fixed-position-ness. But it can also be weird if you use absolute positioning for things. As they will be different depending on if the bar is there or not. Using the code above to remove the bump CSS will make the bar cover the top bit of your site, but at least the positioning will be consistent.

Reference URL

wordpress Remove Specific Categories From The Loop

by in , 0

<?php query_posts('cat=-3'); ?>

<?php if (have_posts()) : ?>

<?php while (have_posts()) : the_post(); ?>

		<h3>

wordpress Remove Private/Protected from Post Titles

by in , 0

For the functions.php file in your theme:

function the_title_trim($title) {

	$title = attribute_escape($title);

	$findthese = array(
		'#Protected:#',
		'#Private:#'
	);

	$replacewith = array(
		'', // What to replace "Protected:" with
		'' // What to replace "Private:" with
	);

	$title = preg_replace($findthese, $replacewith, $title);
	return $title;
}
add_filter('the_title', 'the_title_trim');