Skip to content

Instantly share code, notes, and snippets.

View ivo-ivanov's full-sized avatar
🚀

Ivo Ivanov ivo-ivanov

🚀
View GitHub Profile
@ivo-ivanov
ivo-ivanov / disable-default-gutenberg-blocks
Last active September 23, 2019 07:29
Disable all default gutenberg block types and allow custom blocks #wordpress #gutenberg
//Disable all default block types and allow custom blocks
add_filter( 'allowed_block_types', 'show_only_custom_blocks' );
function show_only_custom_blockss( $allowed_blocks ) {
return array(
'custom-block-category/text',
);
}
@ivo-ivanov
ivo-ivanov / admin-styles
Last active March 4, 2019 11:20
Enque inline admin styles from functions.php #wordpress
add_action('admin_head', 'admin_css');
function admin_css() {
echo '<style>
.acf-gallery .acf-gallery-side-data textarea {
display: none;
}
</style>';
}
@ivo-ivanov
ivo-ivanov / hex-to-rgb.php
Created September 22, 2019 19:13
Convert hex color string to rgb(a) string
/* Convert hexdec color string to rgb(a) string */
function hex2rgba($color, $opacity = false) {
$default = 'rgb(0,0,0)';
//Return default if no color provided
if(empty($color))
return $default;
//Sanitize $color if "#" is provided
@ivo-ivanov
ivo-ivanov / get-the-content
Created September 23, 2019 06:39
Display the post content for specific post ID outside the loop. #wordpress
// with post object by id
$post = get_post(12); // specific post ID
$the_content = apply_filters('the_content', $post->post_content);
if ( !empty($the_content) ) {
echo $the_content;
}
@ivo-ivanov
ivo-ivanov / optimize-wp.php
Last active September 24, 2024 22:36
Optimize WordPress. Remove unnecessary code from wp_head. Disable trackbacks and pings. Disable and remove comments on front-end and back-end. Remove oEmbed functionality. Disable emojis on front-end and remove the tinymce emoji plugin. Remove link tags in header. Remove jQuery Migrate #wordpress
<?php
// Remove Unnecessary Code from wp_head
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_generator');
remove_action( 'wp_head', 'wp_shortlink_wp_head');
remove_action('wp_head', 'start_post_rel_link');
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'adjacent_posts_rel_link');
@ivo-ivanov
ivo-ivanov / custom-gutenberg-category.php
Last active September 23, 2019 07:29
Create custom Gutenberg category. #wordpress #gutenberg
function custom_gutenberg_category( $categories, $post ) {
return array_merge(
$categories,
array(
array(
'slug' => 'custom',
'title' => __( 'Custom', 'custom' ),
),
)
);
@ivo-ivanov
ivo-ivanov / wp-menu-loop.php
Created September 23, 2019 13:44
Loop specific WordPress Menu and display content. #wordpress
<?php
$nav_items = wp_get_nav_menu_items( 'main', array( // name of the specific menu
'order' => 'ASC', // List ASCending or DESCending
'orderby' => 'title', // Order by your usual, menu_order, post_title, etc. Check WP_Query
'post_type' => 'nav_menu_item', // To be honest, I'm not sure why this is an option, leave it be.
'post_status' => 'publish', // If there are private / draft posts in our menu, don't show them
'output' => ARRAY_A, // Return an Array of Objects
'output_key' => 'menu_order', // Not sure what this does
'nopaging' => true, // Not sure what this does
@ivo-ivanov
ivo-ivanov / google-api-acf.php
Last active November 3, 2019 09:28
Enable Google Maps API key for ACF #wordpress
//Enable Google API key for ACF
function my_acf_google_init() {
acf_update_setting('google_api_key', 'XXXXXXXXXXXXXXXXXXX');
}
add_action('acf/init', 'my_acf_google_init');
@ivo-ivanov
ivo-ivanov / bounce.css
Last active March 7, 2021 14:45
Bounce CSS Animation #css
@-moz-keyframes bounce {
0%, 20%, 50%, 80%, 100% {
-moz-transform: translateY(0);
transform: translateY(0);
}
40% {
-moz-transform: translateY(-10px);
transform: translateY(-10px);
}
60% {
@ivo-ivanov
ivo-ivanov / untitled
Created October 9, 2019 16:12
Enable .svg upload in WordPress Mediathek. #wordpress
function add_file_types_to_uploads($file_types){
$new_filetypes = array();
$new_filetypes['svg'] = 'image/svg+xml';
$file_types = array_merge($file_types, $new_filetypes );
return $file_types;
}
add_action('upload_mimes', 'add_file_types_to_uploads');