is_home() is not working in functions.php

Sangwan Pankaj Reply 04:15
At the time functions.php is included during bootup, WordPress has no idea on the contents of the query, and doesn't know the nature of the page. is_home will return false.

Wrap the code in a function and have it triggered by the wp hook, which comes after the global query object has been hydrated with data.


add_action( 'wp', 'check_homepage' );
function
check_homepage() {
    if ( is_home() )
        add_action( 'wp_enqueue_scripts', 'my_scripts' );
}

Limit Words and Characters in content WordPress

Sangwan Pankaj Reply 21:22
add_filter('the_content', 'trim_content');

// This function use to modify you content functions
function trim_content($content){
  $word_limit =30;
  $words = explode(' ', $content);
  return implode(' ', array_slice($words, 0, $word_limit));
}


OR

add_filter('the_content', 'trim_content');

// This function use if  the content having more than 100 charaters it converts into excerpt format.
function trim_content($content)
{
    if(is_archive())
    {
       
// I'm getting the first 100 characters just to show an example you can change the value to get the words..
        $content = (strlen($content) <= 100)? $content : wp_html_excerpt($content, 100);
    }

    return $content;
}
Copyright by GhostPHP. Powered by Blogger.

Search

Recent Post

Popular Posts

Follow us