Skip to content

Instantly share code, notes, and snippets.

View abelsaad's full-sized avatar
😊

abdelrhman aboelsaad abelsaad

😊
View GitHub Profile
@abelsaad
abelsaad / single-service.php
Created May 28, 2021 02:22
WordPress - Display related posts regardless of the post type, custom or otherwise
<?php
// You might need to use wp_reset_query();
// here if you have another query before this one
global $post;
$current_post_type = get_post_type( $post );
// The query arguments
$args = array(
@abelsaad
abelsaad / functions.php
Created May 25, 2021 21:05
Disable WordPress Admin Bar for all users
/* Disable WordPress Admin Bar for all users */
add_filter( 'show_admin_bar', '__return_false' );
@abelsaad
abelsaad / single.php
Created May 19, 2021 23:13
Print Excerpt Limit
<?php echo excerpt(30); ?> - // Change 30 to your own number
@abelsaad
abelsaad / functions.php
Created May 19, 2021 23:09
Content Excerpt Limit
<?php
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
@abelsaad
abelsaad / post-thumbnails.php
Created May 19, 2021 23:08
Post Thumbnails
<img src=" <?php the_post_thumbnail('medium'); ?>">
<?php
// without parameter -> Post Thumbnail (as set by theme using set_post_thumbnail_size())
the_post_thumbnail();
the_post_thumbnail('thumbnail'); // Thumbnail (default 150px x 150px max)
the_post_thumbnail('medium'); // Medium resolution (default 300px x 300px max)
the_post_thumbnail('medium_large'); // Medium Large resolution (default 768px x 0px max)
the_post_thumbnail('large'); // Large resolution (default 1024px x 1024px max)
@abelsaad
abelsaad / functions.php
Created May 19, 2021 23:04
Support Post Thumbnails
<?php
if ( function_exists('add_theme_support') )
add_theme_support('post-thumbnails');
@abelsaad
abelsaad / functions.php
Created May 19, 2021 23:02
Change Wordpress default menu classes
<?php
add_filter('nav_menu_css_class', 'normalize_wp_classes', 10, 2);
// for the page menu fallback (wp_list_pages)
add_filter('page_css_class', 'normalize_wp_classes', 10, 2);
function normalize_wp_classes($classes, $item){
// old class => new class
$replacements = array(
@abelsaad
abelsaad / footer.php
Created May 19, 2021 22:58
Print Widget
@abelsaad
abelsaad / functions.php
Created May 19, 2021 22:53
Register widget area
<?php
function abdo_widgets_init() {
register_sidebar(
array(
'name' => __( 'Car list', 'abdo' ),
'id' => 'car_list',
'description' => __( 'Footer Cars list', 'abdo' ),
'before_widget' => '',
@abelsaad
abelsaad / functions.php
Created May 19, 2021 17:10
Custom Post Type Title Placeholder
<?php
function abdo($title , $post){
if( $post->post_type == 'movie' ){
$my_title = "Movie Title";
return $my_title;
}
return $title;