Skip to content

Instantly share code, notes, and snippets.

View terrytsang's full-sized avatar

Terry Tsang terrytsang

View GitHub Profile
@terrytsang
terrytsang / wp-codesnippet-enable-shortcode-text-widget.php
Last active September 11, 2022 09:56
Enable shortcode in text widgets
<?php
//add thsi code into your theme functions.php
//Enable shortcode in text widget
add_filter('widget_text', 'do_shortcode');
@terrytsang
terrytsang / wp-codesnippet-change-readmore-text.php
Last active September 11, 2022 09:57
Change Read More Text to Continue Reading for Excerpts
<?php
// add this code into your theme functions.php file
function tt_change_excerpt_readmore_text( $more ){
global $post;
return '&hellip; <a class="read-more" href="'.get_permalink($post->ID).'" title="'.esc_attr(get_the_title($post->ID)).'">'.'Continue Reading &raquo;'.'</a>';
}
add_filter('excerpt_more', 'tt_change_excerpt_readmore_text');
@terrytsang
terrytsang / wp-codesnippet-show-post-thumbnail-rss-feed.php
Last active September 11, 2022 09:57
Include the featured image into RSS feed
<?php
//add this code into your theme functions.php file
add_filter('the_content', 'tt_featured_image_in_rss_feed');
function tt_featured_image_in_rss_feed( $content ) {
global $post;
if( is_feed() ) {
if ( has_post_thumbnail( $post->ID ) ){
$prepend = '<div>' . get_the_post_thumbnail( $post->ID, 'medium', array( 'style' => 'margin-bottom: 10px;' ) ) . '</div>';
@terrytsang
terrytsang / wp-codesnippet-new-favicon.php
Last active September 11, 2022 09:57
Add a new Favicon to your WordPress website
<?php
//add this code to your theme functions.php
// add a favicon
function tt_new_favicon() {
echo '<link rel="favicon" type="image/x-icon" href="https://www.yoursite.com/wp-content/uploads/2022/09/favicon.ico" />';
}
add_action('wp_head', 'tt_new_favicon');
@terrytsang
terrytsang / wp-codesnippet-change-footer-text-wp-admin.php
Created September 11, 2022 09:30
Change footer text at WordPress Admin site
@terrytsang
terrytsang / wp-codesnippet-allow_contributor_upload_images.php
Last active September 11, 2022 09:57
Enable contributor to upload images
<?php
//add this code into theme functions.php file
if ( current_user_can('contributor') && !current_user_can('upload_files') ) {
add_action('admin_init', 'allow_contributor_upload_image');
function allow_contributor_upload_image() {
$contributor = get_role('contributor');
$contributor->add_cap('upload_files');
}
<?php
//add this code into your theme functions.php file
//step 1: change the admin login logo to the uploaded media image file
if ( !function_exists('tt_wp_admin_login_logo') ) :
function tt_wp_admin_login_logo() { ?>
<style type="text/css">
body.login div#login h1 a {
background-image: url('https://www.yoursite.com/wp-content/uploads/2022/09/your-logo.jpg');
@terrytsang
terrytsang / wp-codesnippet-change-post-excerpt-length.php
Last active September 11, 2022 09:58
change the default length of your excerpts in your WordPress website
<?php
//add this code into your theme functions.php
add_filter( 'excerpt_length', function($length) {
return 20; //edit the number to the amount of words you want to show in your excerpts
}, PHP_INT_MAX );
@terrytsang
terrytsang / wp-codesnippet-disable-wordpress-search.php
Created September 11, 2022 07:09
Disable WordPress search function
<?php
//add this code into functions.php to disable search
function tt_filter_query( $query, $error = true ) {
if ( is_search() & !is_admin()) {
$query->is_search = false;
$query->query_vars['s'] = false;
$query->query['s'] = false;
// to error
@terrytsang
terrytsang / wp-codesnippet-disable-wordpress-search.php
Created September 11, 2022 07:09
Disable WordPress search function
<?php
//add this code into functions.php to disable search
function tt_filter_query( $query, $error = true ) {
if ( is_search() & !is_admin()) {
$query->is_search = false;
$query->query_vars['s'] = false;
$query->query['s'] = false;
// to error