Tag Archives: wordpress tutorials

wp-bring-back-single-column

Get back the single-column dashboard in Latest WordPress

From WordPress 3.8 version came with new dashboard style. If you want the back old single-column dashboard, So you can you can use the following code.

For getting back the single-column dashboard in WordPress 3.8, you need to add the following code in functions.php file.

// force one-column dashboard
function wpapi_single_screen_layout_columns($columns) {
$columns['dashboard'] = 1;
return $columns;
}
add_filter('screen_layout_columns', 'wpapi_single_screen_layout_columns');

function wpapi_single_screen_layout_dashboard() { return 1; }
add_filter('get_user_option_screen_layout_dashboard', 'wpapi_single_screen_layout_dashboard');

wp-bring-back-single-column

Add different Editor Styles for Custom Post Types in WordPress

Add different Editor Styles for Custom Post Types in WordPress

There is custom post type support added from wordpress 2.9 in wordpress. Many times we create the different types of post type in wordpress and show it i different way. We use the different styles for showing the content types..

Add different Editor Styles for Custom Post Types in WordPress

Add different Editor Styles for Custom Post Types in WordPress

In wordpress we have the visual and html editor. For adding the different styles for custom post types just open your functions.php file put the following code in that file.


function my_editor_style() {
 global $current_screen;
 switch ($current_screen->post_type) {
 case 'post':
 add_editor_style('editor-style-post.css');
 break;
 case 'page':
 add_editor_style('editor-style-page.css');
 break;
 case 'product':
 add_editor_style('editor-style-product.css');
 break;
case 'shop':
 add_editor_style('editor-style-shop.css');
 break;

}
}
add_action( 'admin_head', 'my_editor_style' );

If you are not wordpress developer then dont use above code. In wordpressapi.com site you will find many wordpress tutorials and tips and hacks and plugins. Please write to me on support@wordpressapi.com

send-email-to-wordpress-users

Send email to your Users about new wordpress posts without plugin

For increasing traffic of your wordpress blog or website. It is always good to send email to subscribers about new post.

There are many wordpress plugins available for sending email but I given small code for sending email to wordpress users without using any wordpress pluginss

If you are wordpress developer then only use following code. Open your functions.php file from your theme and put following code in that file. Just copy and paste the following code on your functions.php file:

function send_email_users($post_ID)  {
    global $wpdb;
    $usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;");
    $users = implode(",", $usersarray);
    mail($users, "New Article is Published", 'A new article have been published on http://www.wordpressapi.com. Please visit');
    return $post_ID;
}
add_action('publish_post', 'send_email_users');

You just need to change my domain name to your domain name and put that in your functions.php file. If you are having any issues then Please write to me.
This wordpress hack, tip or trick written by wordpressapi.

Here is some very useful links for wordpress.

Check Following articles for great wordpress hacks of the all the time.

how to create contact us page without wordpress plugin
Add the extra new users details or fields to wordpress without plugin
Display wordpress Tags In A Dropdown Menu without plugin
How to change the Visual Editor Font Size wordpress without plugin
Display wordpress Tags In A Dropdown Menu without plugin
wordpress pagination style without wordpress plugin
show popular posts without wordpress plugin in theme
How to send smtp email through wordpress without plugin
How to put digg button in wordpress without plugin
Get the recent comments without using wordpress plugin or widget
How to Add the social Bookmar Icons in WordPress theme without wordpress plugins
How to exclude pages from wordpress menu without plugin
Show related posts with wordpress post without using any plugin

wordpress-visual-editor-font

How to change the Visual Editor Font Size wordpress without plugin

You need to open your functions.php file and put following code in that file.using following code you can change the font size of editor.

Note: If you are not having knowledge of wordpress code and php then dont use  the code.

add_action( ‘admin_print_styles-post.php’, ‘my_admin_css’ );
add_action( ‘admin_print_styles-post-new.php’, ‘my_admin_css’ );
function my_admin_css() {
?>
<style type=”text/css”>
#editorcontainer textarea#content { font-size: 2em !important }
</style>
<?php

 

Prevent the HTML content in wordpress comments

Prevent the HTML content in wordpress comments

If you are wordpress developer then only use following code. Open your functions.php file from your theme and put following code in that file. Just copy and paste the following code on your functions.php file:

function wordpress_comment_post( $incoming_comment ) {
	$incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']);
	$incoming_comment['comment_content'] = str_replace( "'", '&apos;', $incoming_comment['comment_content'] );
	return( $incoming_comment );
}

function wordpress_comment_display( $comment_to_display ) {
	$comment_to_display = str_replace( '&apos;', "'", $comment_to_display );
	return $comment_to_display;
}
add_filter( 'preprocess_comment', 'wordpress_comment_post', '', 1);
add_filter( 'comment_text', 'wordpress_comment_display', '', 1);
add_filter( 'comment_text_rss', 'wordpress_comment_display', '', 1);
add_filter( 'comment_excerpt', 'wordpress_comment_display', '', 1);

search-wordpress

Add a search from in your navigation menu of wordpress theme

If you are wordpress developer then only use following code. Open your functions.php file from your theme and put following code in that file.

Using following code in you can add the search form in your menu bar.

function add_search_box($items, $args) {
        ob_start();
        get_search_form();
        $searchform = ob_get_contents();
        ob_end_clean();
        $items .= '<li class="search-form">' . $searchform . '</li>';
    return $items;
}
add_filter('wp_nav_menu_items','add_search_box', 10, 2);
wordpress_com_text_widget

Set the style for default search widget

Many people having issue when creating the wordpres theme and show search widget in theme. In this tutorial I will show you how to show default search widget with our custom styling.

you can override the default wordpress search widget.

For that use the following code.


function widget_override_search(){
?>
<li id="linkcat-2">
 <h2> <span>Wordpress Search</span></h2>
 <ul>
<form id="searchform" method="get" action="<?php bloginfo('home'); ?>" style="padding:10px">
<div>
<input type="text" name="s" id="s" size="50" />
<input type="submit" id="searchsubmit" value="<?php echo attribute_escape(__('Search')); ?>" />
</div>
</form>

 </ul>
</li>

<?php
}
if ( function_exists('register_sidebar_widget') )
 register_sidebar_widget(__('Search'), 'widget_override_search');

wordpress-short-code

Disable WordPress Post Revision in wordpress admin

For improving the WordPress website or blog performance you need use following method.

WordPress saves the post revisions after every 2 min. That takes so much mysql storage.
To save MySQL storage, some WordPress user will be happy using this method, this method is Disable WordPress Post Revision.

Why we need disabled this featured?

It’ because WordPress created such as dummy data revision and this one make our table sized increased. And if you have limited space, this is bad idea, and of course disable Post Revision also made your WordPress running faster.

Open your wp-config.php file and put the following code in that file. If you are not wordpress developer then dont use following code. Please consult with any wordpress developer for this code.

/* disable post-revisioning nonsense */
define('WP_POST_REVISIONS', FALSE);
wordpress pagination style without wordpress plugin

wordpress pagination style without wordpress plugin

When we think wordpress pagination style then first thing came in mind which is. We need to install wp-pagenavi wordpress plugin for pagination styling. There are multiple pagination plugins available for pagination styling but wp-pagenavi is most popular.

I always recommend wordpress theme developers to not to use the wordpress plugins as much possible because any wordpress plugin will install the extra unuseful code also.

Here in this article I am giving you the example about wordpress pagination without using any wordpress plugin.

Just open your functions.php file and put following code.


function wpapi_pagination($pages = '', $range = 4)
{
 $showitems = ($range * 2)+1;

 global $paged;
 if(empty($paged)) $paged = 1;

 if($pages == '')
 {
 global $wp_query;
 $pages = $wp_query->max_num_pages;
 if(!$pages)
 {
 $pages = 1;
 }
 }

 if(1 != $pages)
 {
 echo "<div class=\"wpapi_pagination\"><span>Page ".$paged." of ".$pages."</span>";
 if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo; First</a>";
 if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";

 for ($i=1; $i <= $pages; $i++)
 {
 if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
 {
 echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
 }
 }

 if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";
 if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last &raquo;</a>";
 echo "</div>\n";
 }
}

Above function will give the wordpress pagination style like google search engine.

Then open style.css file from your wordpress theme file and put following code in that file.


.wpapi_pagination {
clear:both;
padding:20px 0;
position:relative;
font-size:11px;
line-height:13px;
}

.wpapi_pagination span, .wpapi_pagination a {
display:block;
float:left;
margin: 2px 2px 2px 0;
padding:6px 9px 5px 9px;
text-decoration:none;
width:auto;
color:#fff;
background: #555;
}

.wpapi_pagination a:hover{
color:#fff;
background: #3279BB;
}

.wpapi_pagination .current{
padding:6px 9px 5px 9px;
background: #3279BB;
color:#fff;
}

Then finally where you want to show the wordpress pagination there in area put following code (index.php, etc..)


if (function_exists("wpapi_pagination")) {
 wpapi_pagination($additional_loop->max_num_pages);

wordpress pagination style without wordpress plugin

wordpress pagination style without wordpress plugin

If you are having any issues or question about adding the wordpress pagination without plugin then please write me.

 

 

How to Convert plain text URI to HTML links in wordpress themes

How to Convert plain text URI to HTML links in wordpress themes

When you put some URL and email address you need to manually add the link URL to that text. This action always takes the some time of wordpress blogger. WordPress has facility to add the links to your URL and email address automatically.

This facility is available in wordpress since wordpress 2.7 version but many wordpress theme and plugin developers never used this functionality.

WordPress provides the make_clickable() function for convert plain text URI to HTML links. This function able to convert URI, www, ftp, and email addresses. Finishes by fixing links within links. You just need to pass the string parameter to this method.

More detail information you can find in following file.
wp-includes/formatting.php.

You can use this method in your functions.php file also. Use the following code.

add_filter('the_content', 'make_clickable');

By using this code you are able to covert the URI, www, ftp, and email addresses in to link.

How to Convert plain text URI to HTML links in wordpress themes

How to Convert plain text URI to HTML links in wordpress themes

If you are having any issues or question about make_clickable method then please write to me.