WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Sep 22 2010

Different Favicons for WordPress 3.0 Multisite

Before WordPress 3.0 appeared, I had a different favicon for each of my WordPress sites; however, when I finally made the switch to one WordPress install with Multisite and Domain Mapping, I found that I lost all the various favicons. Typically I use the same two frameworks, and I guess I could create various child theme folders for each site, which would work! However, I'm too lazy to do that and everything that it would entail on enabling themes in the SuperAdmin, etc. (although it would be great to be able to enable themes based on roles!).

So here is what I did in my functions.php file to enable each site in my Multisite installation to have their own favicon. But first, you must place the favicons in the appropriate files folder under wp-content/blogs.dir. So you will need to know the site's ID number, which can be found under the Super Admin > Sites (mydomain.com/wp-admin/ms-sites.php).

[php]/* Different Favicon for Each Site in MS */
function favicon4sites() {
echo '<link rel="Shortcut Icon" type="image/x-icon" href="' . get_bloginfo('wpurl') . '/files/favicon.ico" />';
}
add_action( 'admin_head', 'favicon4sites' );
add_action( 'login_head', 'favicon4sites' );
add_action( 'wp_head', 'favicon4sites' );[/php]

If you wanted, you can write different functions to allow for different favicons for the login screen and the admin section but don't forget to remove add_action( 'login_head', 'favicon4sites' ); and add_action( 'wp_head', 'favicon4sites' ); from the previous edit.

[php]/* Different Favicon for the Admin */
function favicon4admin() {
echo '<link rel="Shortcut Icon" type="image/x-icon" href="' . get_bloginfo('wpurl') . '/wp-content/favicon.ico" />';
}
add_action( 'admin_head', 'favicon4admin' );
[/php]

Also note that you can use *.png or *.gif, but they won't work in IE:

[html]<link rel="icon" href="/favicon.png" type="image/png">
<link rel="icon" href="/favicon.gif" type="image/gif"> [/html]

Written by Travis Smith · Categorized: Tutorials

Sep 03 2010

How to Remove the Category Base URL in WordPress (via kmsm)

Courtesy of Joshua Kelly of kmsm.ca

One of the difficulties with using WordPress as a CMS is that the out-of-the-box URL construction is limited. In this respect, categories have particularly poor control.

By default, WordPress constructs category URLs as http://domain/category/category-name and post URLs as http://domain/date/post-name. While you can control most aspects of the post URLs (whether or not to display the month of the post, for example), the only customization available for category URLs is the base name following the domain in which all categories reside (http://domain/series/category-name, for example).

But this can lead to counterintuitive URLs.

For example, if I file a post about about the Godather under a category called Film, the post URL will read http://domain/2010/01/01/the-godfather while the category URL will read http://domain/category/film. This might work well for a blog format, but for large-scale content management, intuitive URLs are a big deal.

Thankfully, we can get WordPress to do our bidding with a simple hack – and it even works with WordPress 3.0!

Let’s say I want to create post URLs in the form http://domain/category/post-name and category URLs in the form http://domain/category-name. Makes sense right? Well here’s how we do that.

Step One: Edit the Post Permalink

Open up WordPress administration panel, and navigate to the Permalinks options screen. Under Common settings, click Custom Structure and enter /%category%/%postname%/ into the field.

Step Two: Edit Functions.php

To edit the category URL structure we have to go into the functions.php file in our WordPress theme. Before the closing PHP bracket, enter the following:
[php]
add_filter('user_trailingslashit', 'remcat_function');
function remcat_function($link) {
return str_replace("/category/", "/", $link);
}

add_action('init', 'remcat_flush_rules');
function remcat_flush_rules() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}

add_filter('generate_rewrite_rules', 'remcat_rewrite');
function remcat_rewrite($wp_rewrite) {
$new_rules = array('(.+)/page/(.+)/?' => 'index.php?category_name='.$wp_rewrite->preg_index(1).'&paged='.$wp_rewrite->preg_index(2));
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}

[/php]
Make sure to save functions.php and upload it to the theme directory.

Now, to go back to the Godfather example, category URLs will look like http://domain/film and post URLs will appear as http://domain/film/the-godfather. Cool eh?

There are other ways of doing this using .htaccess but this is a cleaner approach in that it modifies how WordPress generates URLs, instead of modifying how the server interprets them.

Written by Travis Smith · Categorized: Tutorials

Jul 27 2010

Using Custom Menus to Create Custom Menus Based on Role/Capabilities

So thanks to Nathan Rice (@nathanrice), creator of Genesis, I was able to complete my code to create menus based on user roles and capabilities. On one of my sites, the user wanted to display three different menus based on one's user roles and capabilities:

  1. One to display if a person was a Contributor or higher (read, edit posts, etc.).
  2. One to display if a person was a Subscribor (read)
  3. One to display for a visitor (none)

So as I stumbled through the code, here is the final code for Genesis Users. For non-Genesis users simply change 'menu_class' => genesis_get_option('nav_superfish') ? 'nav superfish' : 'nav', to 'menu_class' => '',. And you will need to change the add_action and remove_action code.

[php]//Custom Menu Based on Roles/Capabilities
remove_action('genesis_after_header', 'genesis_do_nav');
add_action('genesis_after_header', 'custom_genesis_do_nav');
function custom_genesis_do_nav() {

if ( current_user_can('edit_posts') ) {
$nav = wp_nav_menu(array(
'theme_location' => 'primary',
'menu' => 1,
'container' => '',
'menu_class' => genesis_get_option('nav_superfish') ? 'nav superfish' : 'nav',
'echo' => 0
));
printf( '<div id="nav"><div class="wrap">%s</div></div>', $nav );
}
elseif ( current_user_can('read') && !current_user_can('edit_posts') ) {
$nav = wp_nav_menu(array(
'theme_location' => 'primary',
'menu' => 2,
'container' => '',
'menu_class' => genesis_get_option('nav_superfish') ? 'nav superfish' : 'nav',
'echo' => 0
));
printf( '<div id="nav"><div class="wrap">%s</div></div>', $nav );
}
elseif(!current_user_can('read') && !current_user_can('edit_posts') ) {
$nav = wp_nav_menu(array(
'theme_location' => 'primary',
'menu' => 3,
'container' => '',
'menu_class' => genesis_get_option('nav_superfish') ? 'nav superfish' : 'nav',
'echo' => 0
));
printf( '<div id="nav"><div class="wrap">%s</div></div>', $nav );

}
else //just in case
{
genesis_do_nav();
}

} [/php]

To get the menu id number, simply go to Appearance > Menus. When you mouse over the menus, you should see a URL like http://mydomain.com/wp-admin/nav-menus.php?action=edit&menu=44. The menu=44 is your menu ID. When you click on them the URL should appear in the address bar if you cannot see the URLs in the status bar.

Written by Travis Smith · Categorized: Tutorials

Jul 20 2010

How to Add a Custom Message on the Login or Register Screen

custom  login message
Click for a Larger Image

For one of my projects, I was asked to make the entire WordPress Blog login protected whereby people had to request via a form on the site for access. In doing this everyone was redirected to the login form without a registration link (because they did not want to use the traditional WordPress registration and preferred a manual registration). Anyways, I had to add a message on the login screen to point people to a contact form. Since WordPress 2.8, you can add a custom_login_message. There are a ton of plugins that will help you customize the look of the login screen; however, none that I could find helped you add any text or links to the login screen without simply highjacking the core code or replacing all of the wp-login.php file with a custom one. So here is what you can do:

[php]function custom_login_message() {
$message = "<p class='message'>Welcome, if you haven't already, you need to be <a href='http://photoblog.smithsaga.com/registration/'>registered</a> to see content.</p><br />";
return $message;
}
add_filter('login_message', 'custom_login_message');
?>[/php]

The p class='message' puts the message in a yellow box. If you prefer red, simply change message to login_error.

And if you want a custom message on the registration screen:

[php]function custom_register_message() {
$message = "<p class='message'>Welcome, if you haven't already, you need to be <a href='http://photoblog.smithsaga.com/registration/'>registered</a> to see content.</p><br />";
return $message;
}
add_filter('register_message', 'custom_register_message');
[/php]

Written by Travis Smith · Categorized: Tutorials

Jul 06 2010

Pictorial Tutorial on WordPress Security: Change the WP_ Prefix

The best and most advisable way to do this is to use the plugin called WP Security Scan by Semper Fi Web Design. However, for some people the database table name prefix changing functionality of WP Security Scan doesn’t work. If that is the case, here is how you can do it manually.

1. Deactivate your plugins if you have already installed and activated your plugins.

wordpress security change wp prefix
Click for a Larger Image

2. Backup your wordpress database to a SQL file. If you used Fantastico when you installed your WordPress, it should have told you what the name of the database was. Simply log into PHPMyAdmin, and select that database. When you select that database, you should see something like this: To backup your SQL database, simply go to EXPORT, and then ensure that SQL is selected on the left side, and then click GO. Save the file to whatever location (but remember that location).

wordpress security change wp prefix
Click for a Larger Image

3. First make a second copy of the SQL. To do this, simply click on the file and hit CTRL + C and then CTL + V. This should create the second file with name of "Copy of mySQL.sql". Open the first *.sql file using text editor (using a PC, Notepad ++ is great!; Mac, TextMate is good), then find and replace all ā€œwp_ā€ prefix to ā€œsomething_ā€ (make sure it is in lower case). If you haven't done anything with your blog, then there should be about 50 changes that were made. If there was more then, no worries!

4. Now, you want to drop all tables of your wordpress databases without dropping the database entirely. To do this, simply click on your database on the left side in the blueish sidebar or click STRUCTURE.

wordpress security change wp prefix
Click for a Larger Image

And this will bring you back to the first screen you saw.

wordpress security change wp prefix
Click for a Larger Image

Click CHECK ALL and then change the dropbox "With Selected" to "Drop".

wordpress security change wp prefix
Click for a Larger Image

Which will bring up this screen:

wordpress security change wp prefix
Click for a Larger Image

Click Yes.

5. Next you want to import the *.sql file which has been edited before into your wordpress databases. To do this, simply go to IMPORT, browse and select the appropriate file.

wordpress security change wp prefix
Click for a Larger Image

6. Edit your wp-config.php file and change the $table_prefix = ā€˜wp_’; to $table_prefix = ā€˜something_’;. Typically this will be line 57 (if your wp-config is double-spaced, check line 114-ish or just search for it). Then you are all set! If you are still uncomfortable, I will be glad to help you. Just drop me a note.

Written by Travis Smith · Categorized: Tutorials

  • « Previous Page
  • 1
  • …
  • 14
  • 15
  • 16
  • 17
  • 18
  • Next Page »
  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

Copyright © 2025 ļæ½ WP Smith on Genesis on Genesis Framework ļæ½ WordPress ļæ½ Log in