Skip to content

Instantly share code, notes, and snippets.

@renakdup
Last active December 12, 2022 23:59
Show Gist options
  • Save renakdup/030aed2c3910b4ae3984dfb45c0ff838 to your computer and use it in GitHub Desktop.
Save renakdup/030aed2c3910b4ae3984dfb45c0ff838 to your computer and use it in GitHub Desktop.
WordPress
<?php // enqueues script and style
function rs_enqueues() {
wp_register_style( 'rs_bootstrap', get_template_directory_uri() . '/css/bootstrap-custom.css', false, null );
wp_enqueue_style( 'rs_bootstrap' );
wp_register_script( 'rs_masonry', get_template_directory_uri() . '/js/masonry.pkgd.js', array( 'jquery' ), '1.0.8', true );
wp_enqueue_script( 'rs_masonry' );
wp_deregister_script( 'jquery' );
wp_deregister_script( 'jquery-migrate' );
$inline_style = "
.class{
background-color: ....;
}
";
wp_add_inline_style( 'rs_main', $inline_style );
}
add_action( 'wp_enqueue_scripts', 'rs_enqueues', 100 );
<?php /**
* Function substr the excerpt by type.
*
* @param $type string Type for substr string.
* @param $post post element
*/
function rs_excerpt_length( $type, $post = false ) {
if ( ! $post ) {
global $post;
}
$string = get_the_excerpt( $post );
if ( 'news' == $type ) {
if ( strlen( $string ) > 80 ) {
$string = mb_substr( $string, 0, 80, 'UTF-8' ) . '...';
}
} elseif ( 'bignews' == $type ) {
if ( strlen( $string ) > 99 ) {
$string = mb_substr( $string, 0, 99, 'UTF-8' ) . '...';
}
}
echo $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment