Recommended collection of 10 practical WordPress tips tutorials

Time:2020-1-19

1. Automatically insert text into the WordPress editor
Edit the functions.php file of the current topic directory and paste the following code:

Copy code

The code is as follows:

<?php
add_filter( ‘default_content’, ‘my_editor_content’ );
function my_editor_content( $content ) {
$content = “Mango Station – mango is not sold here, please find another place to buy it. “;
return $content;
}
?>

2. Get the number of registered users of WordPress
With a simple SQL statement, you can easily get the number of registered users of WordPress:

Copy code

The code is as follows:

$users = $wpdb->get_var(“SELECT COUNT(ID) FROM $wpdb->users”);
Echo “has” $users. “Registered users”;

3. Get WordPress articles according to specified custom fields
Pass in the custom field parameter in the query  posts() function to get the corresponding article list:

Copy code

The code is as follows:

<?php query_posts(‘meta_key=review_type&meta_value=movie’); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>

In the parameter, meta_key is to get the name of the custom field, and meta_value is to get the value of the custom field.

4. Get WordPress articles for a certain period of time
To edit the index.php file, just add the following code before the loop body. Of course, you need to change the settings of the time period as needed:

Copy code

The code is as follows:

<?php
function filter_where($where = ”) {
$where .= ” AND post_date >= ‘2009-01-01’ AND post_date <= ‘2010-01-01′”;
return $where;
}
add_filter(‘posts_where’, ‘filter_where’);
query_posts($query_string);
?>

5. Generate an RSS feed for a WordPress tag
As you can see, tags can be separated by commas, so you can also get RSS feeds of multiple tags:
<a href=”http://www.mangguo.org/?feed=rss&tag=query_posts,loop”>
6. Prevent caching of WordPress style files
To prevent clients from reading cache files through server-side settings:

Copy code

The code is as follows:

<link rel=”stylesheet” href=”<?php bloginfo(‘stylesheet_url’); echo ‘?’.filemtime( get_stylesheet_directory().’/style.css’); ?>” >

7. WordPress function for users to count the number of words in Articles
Paste the following code in the functions.php file of the current topic:

Copy code

The code is as follows:

function wcount(){
ob_start();
the_content();
$content = ob_get_clean();
return sizeof(explode(” “, $content));
}

Function call method:

<?php echo wcount(); ?>

8. Prevent WordPress from saving articles automatically
To disable the auto save feature of WordPress, edit the functions.php file and add the following code:

Copy code

The code is as follows:

function disableAutoSave(){
wp_deregister_script(‘autosave’);
}
add_action( ‘wp_print_scripts’, ‘disableAutoSave’ );

9. Goodbye pingbacks / H3 >
Execute the following statement in phpMyAdmin to handle the disgusting pingbacks function with one click.

Update ` wp_posts ` set ping_status = “closed”; 10. Insert author information for WordPress articles
Edit the functions.php file corresponding to the topic and paste the following code:

Copy code

The code is as follows:

function get_author_bio ($content=”){
global $post;
$post_author_name=get_the_author_meta(“display_name”);
$post_author_description=get_the_author_meta(“description”);
$html=”<div class=’clearfix’ id=’about_author’>\n”;
$html.=”<img width=’80’ height=’80’ class=’avatar’ src=’http://www.gravatar.com/avatar.php?gravatar_id=”.md5(get_the_author_email()). “&default=”.urlencode($GLOBALS[‘defaultgravatar’]).”&size=80&r=PG’ alt=’PG’/>\n”;
$html.=”<div class=’author_text’>\n”;
$html.=”<h4>Author: <span>”.$post_author_name.”</span></h4>\n”;
$html.= $post_author_description.”\n”;
$html.=”</div>\n”;
$html.=”<div class=’clear’></div>\n”;
$content .= $html;
return $content;
}
add_filter(‘the_content’, ‘get_author_bio’);

All rights reserved. Please indicate the source of reprint. Mango

Recommended Today

RCAST 35: add type to currency

– font ALT: Simsun; MSO font charset: 134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} @font-face {font-family:”Cambria Math”; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:1; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} @font-face {font-family:Calibri; Variable; Ose-1: 216301111; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} /\* Style […]