Solved: issue with wordpressMU image or media uploading

Many people is having issues with image uploading with WordPressMU. In this article I will tell you the solution. Solved: issue with wordpressMU image or media uploading.

Solved: issue with wordpressMU image or media uploading
Solved: issue with wordpressMU image or media uploading

Solved: issue with wordpressMU image or media uploading

Single wordpress and wordpressMu has different behaviour.. If you are using apache webserver then there is no issue but if you are using than there is issue with image mapping. specially with nginx web server.
You need to write the rewrite rule for image. Also you need to check about folder permission in your “blogs.dir” directory. change folder permission to 777.
For single wordpress there is uploads folder is present but for wordpressMu there is no uploads folder present in directory. You should look for blogs.dir folder which is present in wordpressMu/wp-content folder.

For solve the issue add the following lines in your apache configuration(httpd.conf) file. If this file is not present then add following lines in your .htaccess file.

RewriteEngine On
RewriteBase /

#uploaded files
RewriteRule ^(.*/)?files/$ index.php [L]
RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
RewriteRule ^(.*/)?files/(.*) wp-content/blogs.php?file=$2 [L]

# add a trailing slash to /wp-admin
RewriteCond %{REQUEST_URI} ^.*/wp-admin$
RewriteRule ^(.+)$ $1/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]
RewriteRule  ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

<IfModule mod_security.c>
<Files async-upload.php>
SecFilterEngine Off
SecFilterScanPOST Off
</Files>
</IfModule>

One another issue.
You should check the “Upload File Types” settings going here.
http://yoursite/wp-admin/wpmu-options.php

Check the “Max upload file size” and also check the “Blog upload space”

For Nginx you will find the configuration code from https://purabtech.in/image-upload-issue-in-wordpressmu-with-nginx/

If you have still facing issue with image uploading in wordpressMU. Feel free to write to me or write a comment.

How to get first category name or id from wordpress post

Many people want to know about post category and know more information current category. Some time we need to use the first category of wordpress post. As we know we can define the multiple category to single article. So if we want retrive the wordpress category then we will get the result in simple php array format. Using that array we can easily extract the first category of post.

if we want first category than, we will get result in php array format. Using that array we can easily get first category name or id from wordpress post.

How to get first category name or id from wordpress post

In this post I will show how we can achieve that. Using following code we can get the first category ID.

< ?php
$category = get_the_category();
$currentcat = $category[0]->cat_ID;
?>

Using following code we can extract the first category name from the wordpress post.

< ?php
$category = get_the_category();
$currentcat = $category[0]->cat_name;
?>

Above code we can use only in the loop but using the following code we can extract the category
outside the loop also

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
global $post;
$categories = get_the_category($post->ID);

$currentcat = $category[0]->cat_ID;
?></pre>
<pre>

same like that.. cat name

 <!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
 global $post;
 $categories = get_the_category($post->ID);

$currentcat = $category[0]->cat_name;
 ?>

</pre>
<pre>
How to get first category name or id from post
How to get first category name or id from post

Some best WordPress Hacks for theme developer

there are many wordpress theme deverlopers who are looking for wordpress hacks for theme developer. we have best collection of wordpress hacks for theme developer. Some best WordPress Hacks for theme developer.

wordpress hacks for theme developer

 wordpress hacks for theme developer
wordpress hacks for theme developer

WordPress themes market has grown incredibly. Due to lot of amazing new functionality an synchronization with all social sites.

1. Create TinyURLs with your wordpress site
Open your single.php file and paste the following in the loop:


<?php
echo 'Tiny Url for this post: <a href="'.bloginfo('siteurl').'?p=.'$post->ID.'">'.bloginfo('siteurl').'?p=.'$post->ID.'</a>'
?>

2. Use The Loop To Create An “Archive” Page Template

Create the php page called archive.php and create archive page through wordpress admin and select the archive page template from sidebar option.

In archive.php file you can following code:

<?php
/*
Template Name: Archives
*/
?>

<?php get_header(); ?>

<h2><?php $numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'");
if (0 < $numposts) $numposts = number_format($numposts); ?>
<h2><?php echo $numposts.' recipes published since October 06, 2008'; ?>
</h2>

<ul id="archive-list">
<?php
$myposts = get_posts('numberposts=-1&');
foreach($myposts as $post) : ?>
<li><?php the_time('m/d/y') ?>: <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

3. Create A “Share the article with Facebook” Button
Use the following code in your loop where you want show the facebook share button.

<a href="http://www.facebook.com/sharer.php?u=<?php get_permalink();?>&t=<?php the_title(); ?>" target="blank">Share on Facebook</a>

4. Use More Than One Loop On A Page, Without Printing Duplicate Posts

If you want to use two query post in page or post. you can use following code:

<?php
query_posts('showposts=8');
$ids = array();
while (have_posts()) : the_post();
$ids[] = get_the_ID();
the_title();
the_content();
endwhile;
?>

<?php
query_posts(array('post__not_in' => $ids));
while (have_posts()) : the_post();
the_title();
the_content();
endwhile;
?>

5. Insert Ads After The First Post
If you want show the ad after first post then use the following code:

<?php if (have_posts()) : ?>
<?php $count = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php $count++; ?>
<?php if ($count == 2) : ?>
//Paste your ad code here
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php else : ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>

There are so many wordpress tricks and hack you can found in this website. Search more.

How to exclude pages from wordpress menu without plugin

In this tutorial we will show you How to exclude pages from wordpress menu without plugin. We given simple code for adding to your theme file which will remove pages from menu.

How to exclude pages from wordpress menu without plugin

Normally when we are creating wordpress theme for showing the pages we code as follows

<?php wp_page_menu('show_home=1&amp;menu_class=page-navi&amp;sort_column=menu_order'); ?>
How to exclude pages from wordpress menu without plugin
How to exclude pages from wordpress menu without plugin

As per this code all pages will get displayed in menu. For showing selected pages check the page id.

and then use following code.

<?php 
wp_page_menu('show_home=1&amp;exclude=5,9,23&amp;menu_class=page-navi&amp;sort_column=menu_order'); 
?>

You are able to see the I added the exclude parameter in wordpress method.
Your selected page id for excluding from menu, you need to just put there with comma separated.

Put this code in your header.php file for showing the menu. You are able to exclude the pages from wordpress menu

Show related posts with wordpress post without plugin

For reducing bounce rate Show related posts with wordpress post without plugin is really great solution. There are many wordpress plugins which will give similar functionality but it will add extra code server hits to your server. It causes slowness.

Show related posts with wordpress post

Just copy paste the following code in your functions.php file.  You will find this file in your wordpress theme folder.

Show related posts with wordpress post
Show related posts with wordpress post
function get_related_posts($post_id) {
$tags = wp_get_post_tags($post_id);
if ($tags) {
echo 'Check some Related Posts<br>';
$first_tag = $tags[0]->term_id;
$args=array(
'tag__in' => array($first_tag),
'post__not_in' => array($post->ID),
'showposts'=>10,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post();
$the_permalink = get_permalink();
$post_title =  get_the_title();
$related_post = '<a href="'.$the_permalink.'">'.$post_title.'</a><br>';
echo $related_post;
endwhile;
}
}
}

You just need to use this function in your loop using “get_related_posts();” this function.

Change WordPress login logo using wordpress hack

If you want to Change WordPress login logo using wordpress hack. Just copy paste following lines to your wordpress theme folder’s functions.php file for this. There is very small code snippet you need put in your wordpress theme.

Change WordPress login logo using wordpress hack

function change_login_logo() {
echo ‘<style type=”text/css”>
h1 a { background-image:url(‘.get_bloginfo(‘template_directory’).’/images/logo.png); }
</style>’;
}

add_action(‘login_head’, ‘change_login_logo’);

Change WordPress login logo using wordpress hack
Change WordPress login logo using wordpress hack

have fun!

Tricks for improving WordPress site performance

WordPress, by default, comes uncompressed and sends the uncompressed HTML to the visitor’s browser. we given some Tricks for improving WordPress site performance.

Please use this tricks carefuly because First trick will cause issue to your wordpress site.

First Trick
Improve the  wordpress Blog’s Loading Speed

Tricks for improving WordPress site performance

Create one file called “phpinfo.php” and then upload it to the root of your blog directory:

In phpinfo.php fine copy paste following code.


<?php phpinfo(); ?>

Check on server zlib is enabled or not.

Copy paste the following code in to your header.php file above the Doctype tag.


<?php
ini_set('zlib.output_compression', 'On');
ini_set('zlib.output_compression_level', '1');
?>

This trick will improve your speed upto 50%.

Code taken from following link :
http://www.wprecipes.com/compress-wordpress-output-and-speed-your-blogs-load-speed

Tricks for improving WordPress site performance
Tricks for improving WordPress site performance

Second Trick

Allow More Time For Slow Servers to Upgrade WordPress

Open the wp-admin/includes/files.php file and go to line 448.

For WordPressMU users path is wp-admin/includes/file.php and line no 450.

Find this line

$response = wp_remote_get($url, array('timeout' => 60));

replace with

$response = wp_remote_get($url, array('timeout' => 120));

This will change the server response time to 120 second.

Code taken from following link :
http://www.wprecipes.com/wordpress-upgrade-allow-more-time-for-slow-servers

How to remove curly quotes from WordPress post

While doing the copy and paste from any website is always problem. While coping the code. curly quotes come and you want to convert that into straight quotes. Some time you want to remove curly quotes from WordPress post title or body.

How to remove curly quotes from WordPress post Title and body.

Here we have given following code which can be useful. The apostrophe should be straight not curly in WordPress.

Just Open your functions.php file from your theme folder. If you did not created functions.php file then you can paste this code in your header.php file.

remove_filter('comment_text', 'wptexturize');
remove_filter('the_title', 'wptexturize');
remove_filter('the_content', 'wptexturize');

This will solve your problem.

How to remove curly quotes and use straight quotes then use following code.

function removesmartquotes($content) {
$content = str_replace('&#8220;', '&quot;', $content);
$content = str_replace('&#8221;', '&quot;', $content);
$content = str_replace('&#8216;', '&#39;', $content);
$content = str_replace('&#8217;', '&#39;', $content);

return $content;
}
add_filter('the_content', 'removesmartquotes');
add_filter('comment_text', 'removesmartquotes');

More reference

code snippets which is most useful in functions.php, wordpress
code snippets which is most useful in functions.php, wordpress

In wordpress – wp-includes/default-filters.php file, we have following list of filters which we can override.

/ Display filters
//add_filter('the_title', 'wptexturize');
add_filter('the_title', 'convert_chars');
add_filter('the_title', 'trim');
 
//add_filter('the_content', 'wptexturize');
add_filter('the_content', 'convert_smilies');
add_filter('the_content', 'convert_chars');
add_filter('the_content', 'wpautop');
add_filter('the_content', 'prepend_attachment');
 
//add_filter('the_excerpt', 'wptexturize');
add_filter('the_excerpt', 'convert_smilies');
add_filter('the_excerpt', 'convert_chars');
add_filter('the_excerpt', 'wpautop');
add_filter('get_the_excerpt', 'wp_trim_excerpt');
 
//add_filter('comment_text', 'wptexturize');
add_filter('comment_text', 'convert_chars');
add_filter('comment_text', 'make_clickable', 9);
add_filter('comment_text', 'force_balance_tags', 25);
add_filter('comment_text', 'convert_smilies', 20);
add_filter('comment_text', 'wpautop', 30);
 
add_filter('comment_excerpt', 'convert_chars');
 
//add_filter('list_cats', 'wptexturize');
//add_filter('single_post_title', 'wptexturize');

 

 

How to exclude images from wordpress post

In one of our project, we got the requirement of exclude images from wordpress post while showing post. We have written code for excluding the image from Post.

How to exclude images from wordpress post

you can use following code in functions.php file or you can use in single.php file. These files you can find in wordpress theme folder.

For changing the code you can use the wordpress admin -> editor section.

Above line I added in showing post without image.


<?php
$FormatedContent = content_with_formatting();
$content = the_content();
$postWithoutImage = preg_replace('/<img[^>]+./’,'' $FormatedContent);
echo $postWithoutImage;
?>

In above code we are checking the image tag and replacing with none.

If you want to find all images from post then Use following command.

preg_match_all('/<img[^>]+>/i',YOUR_text, $result);

You need to add following function in your function.php file(Theme files).

function content_with_formatting($more_link_text = ‘(more…)’, $stripteaser = 0, $more_file = ”)
{
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters(‘the_content’, $content);
$content = str_replace(‘]]>’, ‘]]>’, $content);
return $content;
}

If you want to Hide all images using CSS then use following code

img{
display:none;
}

Just put above code in your style.css file.