Archive for the ‘ Wordpress ’ Category

Store the_permalink() as a variable

Posted by

The wordpress function the_permalink() automatically echos the content to the screen.

Sometimes you want to store this value in a variable.

In this case use:


$string = get_permalink();

Store the_title() in a variable

Posted by

The wordpress function the_title() automatically echos the content to the screen.

Sometimes you want to store this value in a variable.

In this case use:


$string = get_the_title();

Unable to locate WordPress Content directory (wp-content)

Posted by

When you try to update/install a WordPress plugin you get the following error:

“Upgrade Plugin: Unable to locate WordPress Content directory (wp-content)”

Add the following code to the end of your wp-config.php file:
if(is_admin()) {
add_filter('filesystem_method', create_function('$a', 'return "direct";' ));
define( 'FS_CHMOD_DIR', 0751 );
}

WordPress Super Cache 403 Forbidden

Posted by

When trying to access cached pages in WordPress you receive a 403 Permission Denied or 403 Forbidden error.

To fix you must add the following line to your wp-config.php (Add it above the WP_CACHE define.) Then clear your cache.
umask( 0022 );

If your PHP runs as a different user to Apache and permissions are strict Apache may not be able to read the PHP generated cache files.

How to highlight sourcecode in WordPress

Posted by

The SyntaxHighlighter Plus plugin allows you to highlight different types of code within your wordpress posts:

CSS example

[sourcecode language=’css’]pre {
white-space: pre-wrap;       /* css-3 */
white-space: -moz-pre-wrap;  /* Mozilla, since 1999 */
white-space: -pre-wrap;      /* Opera 4-6 */
white-space: -o-pre-wrap;    /* Opera 7 */
word-wrap: break-word;       /* Internet Explorer 5.5+ */
}[/sourcecode]

PHP example

[sourcecode language=’php’] [/sourcecode]

The module states it works upto WordPress 2.5 however it is working without any problems on 2.6.

It supports the following languages (the alias for use in the post is listed next to the name):

  • Bash — bash, sh
  • C++ — cpp, c, c++
  • C# — c#, c-sharp, csharp
  • CSS — css
  • Delphi — delphi, pascal
  • Java — java
  • JavaScript — js, jscript, javascript
  • PHP — php
  • Python — py, python
  • Ruby — rb, ruby, rails, ror
  • SQL — sql
  • VB — vb, vb.net
  • XML/HTML — xml, html, xhtml, xslt