FindsGood

  1. How-to
  2. WordPress Tips and Tricks
  3. Posted on Tue, 13 Mar, 2018 at 11:56 AM

WordPress Tips and Tricks

WordPress Tips and Tricks

insert line break
HTML tag in get_the_content(”) of WordPress

08/03/2018 – nl2br(get_the_content(''))

PHP nl2br() Function inserts line breaks where newlines (\n) occur in the string.

The browser output of the code above will be:

One line.
Another line.

The HTML output of the code above will be (View Source):

One line.
Another line.

we use this get_the_content(”) in a loop, tag and category template. not in a single page template. So, nl2br() its automatically inserts line break HTML tag in WordPress content.

How to get the tag’s slug on the tag page in WordPress

28/01/2018 – You can get the slug by getting the queried object while on the tag page, like so:

slug
?>

slug.'/'; ?>

How to get post slug from single post template in wordpress?

28/01/2018 – You can get that using the following methods:

Or You can use this easy code:

post_name;
?>

post_name.'/'; ?>

WordPress posts content update old URLs to new URLs

21/05/2017 – Hi, All. Today I moved to new blog, my blog’s old posts content moved to new blog. and updated all URLs in simple way. Here is SQL Query.

UPDATE wp_posts SET post_content = replace(post_content, 'http://oldurl.com', 'http://mynewblog.com');

  1. Just got to your blog’s SQL admin page, Here i am using phpMyAdmin.
  2. so login to your blog’s database.
  3. Then select your blog’s database.
  4. Then SQL tab to enter SQL Query. just type the above sql query into query box.
  5. then select go button.

So, single click to replacing old URLs to new URLs in blog post’s content is so simple and easy.

How to trim title characters or words length of WordPress blog

28/07/2016 –

 echo mb_strimwidth(get_the_title(), 0, 75, "…"); ?>

How to redirect Javascript disabled WordPress blog page to Noscript page PHP code

25/07/2016 – Some people disable javascript on their browsers. So, your website may not work properly on their browsers who disabled Javascript.
You can redirect javascript disabled pages to noscript page or mobile page.
Then you can request users to enable javascript on their browsers.
Here is the wordpress code to redirect pages to noscript page.

/** php code for header.php page **/
if ( ! is_single() ){echo '
';}?>

if ( is_single() ) { $id = get_the_ID(); if ( $id!=10965 )
{echo '
';}}?>








How to remove WordPress blog comment feed links permanently

30/06/2016 –

  1. If you don’t want to publish your blog’s post comments via feeds.
  2. You can use this code to permanently remove comment feed links.
  3. And redirect comment feed links to your blog address or you can redirect to any URL, If you want.
//This code will redirect all comment URLs to given URL:
function com_disable_feed( $comments ) 
{   if( $comments ) { wp_redirect( 'https://findsgood.com/'); exit; }
}
add_action('do_feed', 'com_disable_feed',1 );
add_action('do_feed_rdf', 'com_disable_feed',1 );
add_action('do_feed_rss', 'com_disable_feed',1 );
add_action('do_feed_rss2', 'com_disable_feed',1 );
add_action('do_feed_atom', 'com_disable_feed',1 );

//Removes single post comment feed links:
function remove_comments_rss( $for_comments ) {
return;
}
add_filter('post_comments_feed_link','remove_comments_rss');

/** Removes main home URL feed link and main comment feed link so you can add home feed URL manually: **/
remove_action( 'wp_head', 'feed_links', 2 );
  1. insert line break
    HTML tag in get_the_content(”) of WordPress
  2. How to get the tag’s slug on the tag page in WordPress
  3. How to get post slug from single post template in wordpress?
  4. WordPress posts content update old URLs to new URLs
  5. How to trim title characters or words length of WordPress blog
  6. How to redirect Javascript disabled WordPress blog page to Noscript page PHP code
  7. How to remove WordPress blog comment feed links permanently
Follow YouTube