Skip to content

Instantly share code, notes, and snippets.

View abelsaad's full-sized avatar
😊

abdelrhman aboelsaad abelsaad

😊
View GitHub Profile
@abelsaad
abelsaad / wordpress-breadcrumbs.php
Last active May 18, 2021 13:25
how to create custom breadcrumbs in wordpress without plugin
<?php
function custom_breadcrumbs() {
// Settings
$separator = '<svg version="1.1" id="arrow" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 492.004 492.004" style="width: 8px;height: auto;" xml:space="preserve"><g><g><path d="M382.678,226.804L163.73,7.86C158.666,2.792,151.906,0,144.698,0s-13.968,2.792-19.032,7.86l-16.124,16.12
c-10.492,10.504-10.492,27.576,0,38.064L293.398,245.9l-184.06,184.06c-5.064,5.068-7.86,11.824-7.86,19.028
c0,7.212,2.796,13.968,7.86,19.04l16.124,16.116c5.068,5.068,11.824,7.86,19.032,7.86s13.968-2.792,19.032-7.86L382.678,265
c5.076-5.084,7.864-11.872,7.848-19.088C390.542,238.668,387.754,231.884,382.678,226.804z"></path></g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g></svg>';
$breadcrums_id = 'breadcrumbs';
@abelsaad
abelsaad / randomize-uploaded-file-name.php
Last active January 26, 2021 09:45
WordPress Random name for uploaded files
<?php
// randomize upload filenames
function htg_randomize_uploaded_filename( $filename ) {
// does it have an extension? grab it
$ext = empty( pathinfo( $filename )['extension'] ) ? '' : '.' . pathinfo( $filename )['extension'];
// return the first 8 characters of the MD5 hash of the name, along with the extension
return substr(md5($filename), 0, 8) . $ext;
@abelsaad
abelsaad / breadcrumbs-short-code.php
Last active May 18, 2021 13:24
breadcrumbs short code
// Then use the short code
<?php custom_breadcrumbs(); ?>
@abelsaad
abelsaad / disable-install-new-theme.php
Created January 14, 2021 08:50
Disable Install New Theme Button
<?php
function __block_caps( $caps, $cap ) {
if ( $cap === 'install_themes' )
$caps[] = 'do_not_allow';
return $caps;
}
add_filter( 'map_meta_cap', '__block_caps', 10, 2 );
@abelsaad
abelsaad / wp-logo-from-the-adminbar.hpp
Created January 14, 2021 08:51
Remove the WP Logo from the Toolbar
<?php
function remove_wp_logo( $wp_admin_bar ) {
$wp_admin_bar->remove_node( 'wp-logo' );
}
add_action( 'admin_bar_menu', 'remove_wp_logo', 999 );
@abelsaad
abelsaad / custom-menus-classes.php
Created January 14, 2021 08:53
WordPress Custom Menus 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(
// RTL Support
function enqueue_theme_files() {
wp_enqueue_style( 'themeslug-style', get_stylesheet_uri() );
wp_style_add_data( 'themeslug-style', 'rtl', 'replace' );
}
add_action( 'wp_enqueue_scripts', 'enqueue_theme_files' );
<?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
<?php
//for each category, show all posts
$cat_args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories=get_categories($cat_args);
foreach($categories as $category) {
$args=array(
'showposts' => -1,
@abelsaad
abelsaad / Style.css
Created May 18, 2021 12:01
Theme Stylesheet
/*
Theme Name: Your Theme Name
Theme URI: https://www.your-site.com/
Description: The 2021 default theme for WordPress.
Author: Abdulrhman Ahmed
Author URI: https://www.aboelsaad.com/
Version: 1.0
Tags: blue, white, two-columns, translation-ready, rtl-language-support, custom-menu (optional)
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html