OK, first of all, I didn’t come up with these. I’ve found them through trial and error whilst wrestling a WordPress project I’m working on into submission and then tweaked them to my needs. They are in no particular order but if you are working on a WordPress template file in PHP, the following may come in useful….

Truncate the Permalink/title text

Say you want the Permalink in a sidebar or similar and want to truncate the length…

$getlength = strlen($thetitle);
$thelength = 39;
echo substr($thetitle, 0, $thelength);
if ($getlength > $thelength) echo "...";

Display all thumbnails from a particular category and link to the relevant post
We’re also using the truncate trick from above here to limit the post title, omit this part if needed.

 45, 'order'=> 'ASC', 'orderby' => 'title' );
$postslist = get_posts( $args );
foreach ($postslist as $post) :  setup_postdata($post); ?> 

Remove the automatic < p > tag from posts/pages

If you are inserting video onto a page you often don’t want the player wrapped in a tag for validation. Stick this line in the relevant template’s functions.php file to remove it:

remove_filter ('the_content', 'wpautop');

Use Google’s CDN for jQuery and correctly add your own jQuery/javascript files

This chunk of code needs to go into your functions.php file for the theme/child-theme you are developing for. As you can see, the first couple of lines un-register the standard jQuery and then re-register the Google CDN one. After that we tell it to load the megamenu.js file by looking in the stylesheet directory and moving in to the js directory.

One other thing that is worth mentioning, for happy times using jQuery and WordPress together, and avoid conflicts by amending your scripts to replace the ‘$’ character with ‘jQuery’.

//use google's jquery
if (!is_admin()){
wp_deregister_script( 'jquery' );
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');
wp_enqueue_script('megamenu', get_bloginfo('stylesheet_directory') . '/js/megamenu.js');

add_action('template_redirect', 'my_init_method');

Display a category name by ID outside ‘The Loop’

< ?php echo get_cat_name(4);?>

Obviously just change the number in brackets to the ID number of the category title you want to display.

Truncate the category description

First paste this into your theme/child-theme’s functions.php file:

 $word_limit )
   $string = substr( $string, 0, strrpos( substr($string, 0, 35), ' ' ) )
. '[...]';
 return $string;

Then, in your template file, use the following (changing ’10’ for whatever character length you need)

" . limit_words( category_description(1), 42 ) . "

"; ?>