Wednesday 30 July 2014

How to Run php Code in Wordpress Widget

Hi ,
Today we learn How to Run php Code in Wordpress Widget  ?  Normally if you Write php Code  Wordpress Widget , This code will won't Work .So if you want to Support your php code into wordpress text widget . you need to Follow this code paste into your theme function.php File .

add_filter('widget_text', 'enable_php_code', 99);
function enable_php_code ($text) {
if (strpos($text, '
ob_start();
eval('?' . '>' . $text);
$text = ob_get_contents();
ob_end_clean();
}
return $text;
}

Now you can write you php code into wordpress test widget . try it now and enjoy 

Here Is more use full WordPress Resource :

Best WordPress Page Builder

How to Short Wordpress title in Frontend ?

Hi,
Today We will Show you How to Short your WordPress Title  in  Front-end   . Many Time we need Short Our wordpress Title  .  My One client Give me one PSD to convert into Wordpress . So When I complete there i saw some problem in Home page  , as some post title are going to too long . so Changed grid in Home page . this shown totally ugly . So I try solve this and solve this  .

if you want do this just Follow this 2 step ,

Step 1: this code paste in your loop


<?php if (strlen(the_title('','',FALSE)) > 50) { //Character length
          $title_short = substr(the_title('','',FALSE), 0, 50); // Character length
          preg_match('/^(.*)\s/s', $title_short, $matches);
      if ($matches[1]) $title_short = $matches[1];
          $title_short = $title_short.' ...'; // Ellipsis
      } else {
          $title_short = the_title('','',FALSE);
      } ?>
Step 2 : and Paste this where you want to show your title 
<?php echo $title_short ?>
See this Example  
<?php if(have_posts()) : ?>
                    <?php while (have_posts()) : the_post(); ?>       
                <div class="col-md-4 looppost">
                    <div class="post">
<?php if (strlen(the_title('','',FALSE)) > 50) { //Character length
          $title_short = substr(the_title('','',FALSE), 0, 50); // Character length
          preg_match('/^(.*)\s/s', $title_short, $matches);
      if ($matches[1]) $title_short = $matches[1];
          $title_short = $title_short.' ...'; // Ellipsis
      } else {
          $title_short = the_title('','',FALSE);
      } ?>
                        <h2><a href="<?php the_permalink()?> "><?php echo $title_short ?></a></h2>
                        <?php endwhile; ?>      <?php endif; ?>