Now, what a about if We want to hide only a part of the post? This code snippet will show You how to do it.
First, you need to put the code below to function.php file in your active theme. After that, to hide an element or part in the post, you have to put that part between [hide] and [/hide] tags.
For example: [hide]Hidden paragraph bla bla[/hide]
The Non-logged in visitor now can’t read the text between those two tags
Here’s the code for function.php :
function Wp_UCanHide($text) { global $user_ID; if ($user_ID == '') { $posdebut = strpos($text, '[hide]'); $posfin = strpos($text, '[/hide]'); $posfin = $posfin + 5; $texttohide = substr($text,$posdebut,$posfin); $text = str_replace($texttohide, "", $text); return $text; }else{ $text = str_replace('[hide]', "", $text); $text = str_replace('[/hide]', "", $text); return $text; } } // Apply the filters, to get things going add_filter('the_content', 'Wp_UCanHide');
Hope this tutorial helps.
Credits:
The code is taken from WP UCanHide plugin, http://wordpress.org/extend/plugins/wp-ucanhide/, with a lithe modification.
For some reason, maybe you want to exclude one or two categories for the list. This can be achieved by hacking the_category function, or create a new code to list the category, to replace the_category.
Most of the tutorials I found are using the first, by hacking the_category function. This snippet will do the second one.
<?php foreach((get_the_category()) as $category) { if ($category->cat_name != 'cat_to_exclude') { echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> '; } } ?>
The code above is to list post’s categories, where category ‘cat_to_exclude’ will be exclude from the list. You can use this code to replace the_category function in your theme.
Hope this snippet helps
Our 646-364 exams provide you 100% pass guarantee.You can get access to mcts with multiple prep resources of ccent.
]]>One of the tab is Links tab. This tab is to add a new link, edit existing links or create link categories. Links create in here will be display in the blogroll section of your blog.
Often, people doesn’t use this tab at all, so simplifying the admin panel by removing the tab can be done. To remove the tab, simply put the code below in your theme functions.php file.
add_action( 'admin_init', 'remove_links_tab_menu_pages' ); function remove_links_tab_menu_pages() { remove_menu_page('/category/tutorial/feed/link_manager.html'); remove_menu_page('/category/tutorial/feed/tools.html'); }
Hope this code helps.
Credit : The code is taken from http://wordpress.org/extend/plugins/remove-links-page
]]>Once your WP site has been set up to use a static front page, You maybe need the URL of the page that has been designated as the blog page.
Here’s the code to get the link:
<?php $posts_page_id = get_option( 'page_for_posts'); $posts_page = get_page( $posts_page_id); $posts_page_title = $posts_page->post_title; $posts_page_url = get_page_uri($posts_page_id ); ?>
$posts_page_url is the url to blog page and $posts_page_title is the page title
Now You can use it in HTML a tag to link to your blog page, for example:
<a href="<?php echo $posts_page_url; ?>" title="<?php echo $posts_page_title; ?>">blog</a>
Hope this post helps
]]>Simply put the code into your theme functions.php.
function mypo_parse_query_useronly( $wp_query ) { if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp_admin/edit.html' ) !== false ) { if ( !current_user_can( 'level_10' ) ) { global $current_user; $wp_query->set( 'author', $current_user->id ); } } } add_filter('parse_query', 'mypo_parse_query_useronly' );
Hope the snippet helps.
Credit :
Code is taken from Allen Hollman Manage Your Post Only plugin
Simply put the code below in the function.php of your theme.
function searchcategory($query) { if ($query->is_search) { $query->set('cat','2,5'); } return $query; } add_filter('pre_get_posts','searchcategory');
This code will make, only post from category with ID 2 and 5 display on the search result.
Hope this tutorial help.
]]>We can create the drop cap to by giving some styles to first letter of the post. But first we have to give a class to that first letter so we can give it the style. actually, There is a css selector for first letter. You can read a drop cap tutorial here:link. Unfortunately, the selector doesn’t work in old browser. Yes, some users are still using ie6
Here’s the script to add a class to first letter of the post. Simply put the code to your theme function.php
function post_first_letter($content = '') { $pattern = '/<p( .*)?( class="(.*)")??( .*)?>((|\s)*)(("|“|‘|‘|“|\')?[A-Z])/U'; $replacement = '<p><span title="$7" class="post-first-letter">$7</span>'; $content = preg_replace($pattern, $replacement, $content, 1 ); return $content; } add_filter('the_content', 'post_first_letter');
Now, the first letter comes with post-first-letter class, which you can add your drop cap style.
Here’s example style that You can place in the theme style.css file
.post-first-letter { font-size: 50px; float: left; margin-top: 14px; margin-right: 5px; }
Credit:
The code is taken from : drop cap plugin
Sometimes, You might want to automatically limit the length of post title in the main page. This little wordpress hack will allow you to limit the displayed post title by a defined number of characters on your blogs home page.
The code snippet below should be placed somewhere within your wordpress themes functions.php. If your wordpress theme does not have a functions.php file simply create one with your favourite text editor and place it in your wordpress themes folder.
function titlelimitchar($title){ if(strlen($title) > 55 && !(is_single()) && !(is_page())){ $title = substr($title,0,55) . ".."; } return $title; } add_filter( 'the_title', 'titlelimitchar' );
This code will limit post title in the homepage to 55 characters. If the title is more than 55 chars, it will be cut off and “..” will be added in the end of title.
Hope this code help
]]>In my recent project, I need to bold first few words in excerpt. I’ll share the solution here.
Simply put the codes below to your theme’s function.php file
function excerpt_bold($text) { $text = explode(' ',get_the_excerpt()); $text[0]='<strong>'.$text[0]; $text[4]=$text[4].'</strong>'; $text = implode(' ',$text); return $text; } add_filter ('the_excerpt', 'excerpt_bold');
This code will bold first five words. You can change it to other number by replacing ’4′ in the code. But remember, the number should be number of bolded words reduced by one. If You want to bold 8 words, for example, then replace it with 7.
Hope this code snippet helps.
Credit :
Thanks to Alchymith and itsalltech1 at WordPress.org
Often, We need to edit, delete or mark certain comments as spam. Yes, You can delete or mark them as spam via admin panel, but it would be really nice if We can do it from the blog. By default, WordPress shows the “Edit” link on comments (using the edit_comment_link() function) but not “Delete” or “Spam” links/buttons.
You can read our other tutorial about comment section here :
Ok, here’s the script to add those buttons.
Open your theme’s functions.php file and paste the following code :
function spam_delete_comment_link($id) { global $comment, $post; if ( $post->post_type == 'page' ) { if ( !current_user_can( 'edit_page', $post->ID ) ) return; } else { if ( !current_user_can( 'edit_post', $post->ID ) ) return; } $id = $comment->comment_ID; if ( null === $link ) $link = __('Edit'); $link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . __( 'Edit comment' ) . '">' . $link . '</a>'; $link = $link . ' | <a href="'.admin_url("comment.php?action=cdc&c=$id").'">del</a> '; $link = $link . ' | <a href="'.admin_url("comment.php?action=cdc&dt=spam&c=$id").'">spam</a>'; $link = $before . $link . $after; return $link; } add_filter('edit_comment_link', 'spam_delete_comment_link');
That’s all. Hope This snippet useful for You
credit : wprecipes and smashingmagazine
]]>