Skip to content

Instantly share code, notes, and snippets.

@Lego2012
Created January 26, 2025 11:11
Show Gist options
  • Save Lego2012/6d3b7d0720e906718233240c925a632b to your computer and use it in GitHub Desktop.
Save Lego2012/6d3b7d0720e906718233240c925a632b to your computer and use it in GitHub Desktop.
<?php
/**
* Register/enqueue custom scripts and styles
*/
add_action( 'wp_enqueue_scripts', function() {
// Enqueue your files on the canvas & frontend, not the builder panel. Otherwise custom CSS might affect builder)
if ( ! bricks_is_builder_main() ) {
wp_enqueue_style( 'bricks-child', get_stylesheet_uri(), ['bricks-frontend'], filemtime( get_stylesheet_directory() . '/style.css' ) );
}
} );
/**
* Register custom elements
*/
add_action( 'init', function() {
$element_files = [
__DIR__ . '/elements/title.php',
];
foreach ( $element_files as $file ) {
\Bricks\Elements::register_element( $file );
}
}, 11 );
/**
* Add text strings to builder
*/
add_filter( 'bricks/builder/i18n', function( $i18n ) {
// For element category 'custom'
$i18n['custom'] = esc_html__( 'Custom', 'bricks' );
return $i18n;
} );
/**
* WordPress Logout Weiterleitung
*/
function redirect_after_logout(){
wp_redirect( home_url() );
exit();
}
add_action('wp_logout', 'redirect_after_logout');
/**
* WordPress Clean Dashboard
*/
function bt_remove_dashboard_widgets() {
remove_action( 'welcome_panel', 'wp_welcome_panel' ); // Welcome Panel
remove_meta_box( 'dashboard_site_health', 'dashboard', 'normal' ); // Remove Health
remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' ); // Quick Press Widget
remove_meta_box( 'dashboard_right_now', 'dashboard', 'normal' ); // Right now
remove_meta_box( 'dashboard_activity', 'dashboard', 'normal' ); // Activity
remove_meta_box( 'dashboard_primary', 'dashboard', 'side' ); // WordPress.com Blog
remove_meta_box( 'dashboard_recent_drafts', 'dashboard', 'side' ); // Recent Drafts
remove_meta_box( 'dashboard_activity', 'dashboard', 'normal' ); // Activity
remove_meta_box( 'dashboard_site_health', 'dashboard', 'normal' ); // Remove Health
}
add_action( 'wp_dashboard_setup', 'bt_remove_dashboard_widgets' );
/**
* Image Sizes by Geary
*/
add_theme_support( 'post-thumbnails' );
add_image_size( 'image-480', 480, 9999 );
add_image_size( 'image-640', 640, 9999 );
add_image_size( 'image-720', 720, 9999 );
add_image_size( 'image-960', 960, 9999 );
add_image_size( 'image-1168', 1168, 9999 );
add_image_size( 'image-1440', 1440, 9999 );
add_image_size( 'image-1920', 1920, 9999 );
function my_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'image-480' => 'image-480',
'image-640' => 'image-640',
'image-720' => 'image-720',
'image-960' => 'image-960',
'image-1168' => 'image-1168',
'image-1440' => 'image-1440',
'image-1920' => 'image-1920',
) );
}
add_filter( 'image_size_names_choose', 'my_custom_sizes' );
// Get rid of WP Image Sizes
function add_image_insert_override($sizes)
{
unset($sizes["thumbnail"]);
unset($sizes["medium"]);
unset($sizes["medium_large"]);
unset($sizes["large"]);
unset($sizes["full"]);
return $sizes;
}
add_filter("intermediate_image_sizes_advanced", "add_image_insert_override");
/**
* Bricks Custom Tags
*/
add_filter('bricks/elements/text-basic/controls', function ($controls) {
$controls['tag'] = [
'tab' => 'content',
'label' => esc_html__('HTML tag', 'bricks'),
'type' => 'select',
'options' => [
'div' => 'div',
'p' => 'p',
'span' => 'span',
'figcaption' => 'figcaption',
'address' => 'address',
'figure' => 'figure',
'ul' => 'ul',
'li' => 'li',
'custom' => esc_html__('Custom', 'bricks'),
],
'lowercase' => true,
'inline' => true,
//'placeholder' => 'p',
'default' => 'p',
];
$controls['customTag'] = [
'tab' => 'content',
'label' => esc_html__('Custom tag', 'bricks'),
'type' => 'text',
'inline' => true,
'placeholder' => 'div',
'required' => ['tag', '=', 'custom'],
];
return $controls;
});
/**
* Befreit den Header von unnötigen Einträgen
* https://www.drweb.de/wordpress-snippets/
*/
add_action('init', 'evolution_remheadlink');
function evolution_remheadlink()
{
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'parent_post_rel_link', 10, 0);
remove_action('wp_head', 'start_post_rel_link', 10, 0);
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
remove_action('wp_head', 'wp_shortlink_header', 10, 0);
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
}
/**
* FancyBricks Templates
* Bricks in the latest version has blocked the custom tags and you must allow them:
* https://academy.bricksbuilder.io/article/filter-bricks-allowed_html_tags/
* Add the following code in the functions.php file:
*/
add_filter( 'bricks/allowed_html_tags', function( $allowed_html_tags ) {
// Define the additional tags to be added (e.g. 'form' & 'select')
$additional_tags = ['form', 'select', 'svg', 'defs', 'path', 'text', 'textPath', 'progress', 'img-comparison-slider', 'bar', 'time', 'li', 'ul','input','progressbar'];
// Merge additional tags with the existing allowed tags
return array_merge( $allowed_html_tags, $additional_tags );
} );
/**
* Add featured image column to WP admin panel - posts AND pages
* See: https://bloggerpilot.com/featured-image-admin/
*/
// Set thumbnail size
add_image_size( 'j0e_admin-featured-image', 60, 60, false );
// Add the posts and pages columns filter. Same function for both.
add_filter('manage_posts_columns', 'j0e_add_thumbnail_column', 2);
add_filter('manage_pages_columns', 'j0e_add_thumbnail_column', 2);
function j0e_add_thumbnail_column($j0e_columns){
$j0e_columns['j0e_thumb'] = __('Image');
return $j0e_columns;
}
// Add featured image thumbnail to the WP Admin table.
add_action('manage_posts_custom_column', 'j0e_show_thumbnail_column', 5, 2);
add_action('manage_pages_custom_column', 'j0e_show_thumbnail_column', 5, 2);
function j0e_show_thumbnail_column($j0e_columns, $j0e_id){
switch($j0e_columns){
case 'j0e_thumb':
if( function_exists('the_post_thumbnail') )
echo the_post_thumbnail( 'j0e_admin-featured-image' );
break;
}
}
// Move the new column at the first place.
add_filter('manage_posts_columns', 'j0e_column_order');
function j0e_column_order($columns) {
$n_columns = array();
$move = 'j0e_thumb'; // which column to move
$before = 'title'; // move before this column
foreach($columns as $key => $value) {
if ($key==$before){
$n_columns[$move] = $move;
}
$n_columns[$key] = $value;
}
return $n_columns;
}
// Format the column width with CSS
add_action('admin_head', 'j0e_add_admin_styles');
function j0e_add_admin_styles() {
echo '<style>.column-j0e_thumb {width: 60px;}</style>';
}
/**
* Add "inner" class to 'body' element for inner pages
* i.e., for all pages other than site's homepage/front page.
*
* @author Sridhar Katakam
* @link http://sridharkatakam.com/add-inner-body-class-inner-pages-wordpress/
*/
function sk_body_class( $classes ) {
if ( ! is_front_page() ) {
$classes[] = 'inner';
}
return $classes;
}
add_filter( 'body_class', 'sk_body_class' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment