Make .htaccess and other hidden files appear in the Finder

When developing in a Mac OS X environment you quite often find yourself wondering why some files doesn’t show up in Finder. If you’re developing for WordPress, you might wonder where your .htaccess file is. This is because Mac OS X hides Unix files.

To show hidden files in Finder, open up the Terminal and paste the following code

defaults write com.apple.Finder AppleShowAllFiles YES

For it to have effect you need to restart Finder. To reset Finder, hold the Option key, click the Finder icon in the dock and hold it until the menu pops up and choose “Restart”.

Tagged with: ,
Posted in Misc

Remember to use the Shortcode API

The Shortcode API is an excellent way to embed HTML code in your posts and pages without much effort from the user.

In a recent project we had great use of the Shortcode API when we needed parts of our content styled inside a box. Simple enough for the shortcode!

We wanted something like

[box]
This content will be in a box!
[/box]

To be presented as:

<div class="box">
<p>This content will be in a box!</p>
</div>

To do so, just create a simple function and hook it up to the box shortcode (or any shortcode of your choice, just replace the first argument in the add_shortcode function). The function can take three arguments but I’m only using two. First one is $atts which is an array of the attributes and the second is $content which contains all the enclosed content.

function box_shortcode($atts, $content = null){
extract(shortcode_atts(array(
"class" => false
), $atts));

return "<div class=\"box" . ($class ? " " . $class : "" ) . "\">" . $content . "</div>";
}
add_shortcode("box", "box_shortcode");

While validating the HTML code I noticed that some wierd p tags sometimes appeared. So I got rid of them with two lines of code.

$content = preg_replace("/^<\/p>/", "", $content);
$content = preg_replace("/<p>$/", "", $content);

There you have it!

function box_shortcode($atts, $content = null){
extract(shortcode_atts(array(
"class" => false
), $atts));

$content = preg_replace("/^<\/p>/", "", $content);
$content = preg_replace("/<p>$/", "", $content);

return "<div class=\"box" . ($class ? " " . $class : "" ) . "\">" . $content . "</div>";
}
add_shortcode("box", "box_shortcode");

Besides boxes I’ve created formated v-cards, contact lists and much more with the Shortcode API. See the WordPress codex for more detailed information.

Tagged with:
Posted in Intermediate

Custom CSS class for your menu items

When using the wp_list_pages function in WordPress you get a generated list of your WordPress pages.

To be able to style them, the items get several CSS classes.

Example:

<li class="page_item page-item-2"><a title="About" href="https://wpquicktips.wordpress.com/about/">About</a></li>

These classes work in most cases, but in thoose cases they don’t you can change the class by using the filter page_css_class.

The function accepts two arguments, $css_class and $page. The first is an array of all the CSS classes and the second is a Post object.

Working example:

function menu_css_class($css_class, $page){
 $new_class[] = "m-" . $page->post_name;

 if(in_array("current_page_item", $css_class))
 $new_class[] = " m-" . $page->post_name . "-sel";

 return $new_class;
}
add_filter("page_css_class", "menu_css_class", 10, 2);

In this function I check if the current array contains the default “selected class”. If so, I add a second CSS class to the new array I’ve created. This is just a quick way to check if an item is selected, but it’s not very fool proof.

Already added to the array is a CSS class that will look something like “m-the-post-slug”.

Return the array and you’re done!

Tagged with: , ,
Posted in Beginner
About

WordPress Quick Tips is a blog supplying great tips about WordPress.

We hope to create a great knowledge resource for WordPress developers as well as serving a reminder for all the forgetful ones.

The blog is created and run by Vincent of Oakwood Creative

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 13 other subscribers
Design a site like this with WordPress.com
Get started