Skip to content

Instantly share code, notes, and snippets.

View certainlyakey's full-sized avatar

Aleksandr Beliaev certainlyakey

  • Nortal AS
  • Tallinn
View GitHub Profile
@certainlyakey
certainlyakey / functions.php
Created March 16, 2018 10:09
Add a hint on the media upload screen in admin (Wordpress)
<?php
function upload_hint() {
global $common_config;
$adminscreen = get_current_screen();
echo '<p>';
_e('Consider uploading images of at least 1050 pixels in width.','site');
echo '</p>';
@certainlyakey
certainlyakey / functions.php
Created March 16, 2018 10:01
Remove unwanted buttons from TinyMCE editor (Wordpress)
<?php
function tiny_mce_remove_unused_buttons_row_1($buttons) {
$remove = array('wp_more', 'aligncenter', 'alignleft', 'alignright');
return array_diff($buttons,$remove);
}
add_filter('mce_buttons','tiny_mce_remove_unused_buttons_row_1');
@certainlyakey
certainlyakey / functions.php
Created March 16, 2018 09:56
Add a placeholder to post title in admin (Wordpress)
<?
// Add placeholder text to an office title
function change_placeholder_text_offices($title){
$screen = get_current_screen();
if ( $screen->post_type == 'office' ) {
$title = 'Enter city name here';
}
return $title;
}
@certainlyakey
certainlyakey / functions.php
Created March 16, 2018 09:50
Remove unwanted TinyMCE items from ACF Wysiwyg editor field toolbar (Wordpress)
<?php
function acf_add_wysiwyg_toolbar($toolbars) {
$toolbars['Bare'] = array();
$toolbars['Bare'][1] = array('bold', 'italic', 'link', 'unlink', 'removeformat');
return $toolbars;
}
add_filter('acf/fields/wysiwyg/toolbars', 'acf_add_wysiwyg_toolbar');
@certainlyakey
certainlyakey / functions.php
Created March 16, 2018 09:47
Disable Custom fields menu item in the admin (Wordpress + ACF)
<?php
// Disable "Custom fields" menu in admin
add_filter('acf/settings/show_admin', '__return_false');
@certainlyakey
certainlyakey / functions.php
Last active March 16, 2018 11:37
Add a placeholder to TinyMCE editor (Wordpress)
<?php
function set_mce_editor_placeholder_question($textarea_html) {
if ('question' !== get_post_type()) return $textarea_html;
$placeholder = __( 'Please enter some text as the question...', 'site_domain');
$textarea_html = preg_replace( '/<textarea/', "<textarea placeholder=\"{$placeholder}\"", $textarea_html );
return $textarea_html;
@certainlyakey
certainlyakey / functions.php
Created March 16, 2018 09:26
Remove formats (text styles) TinyMCE editor (Wordpress)
<?php
// Modify TinyMCE editor to remove H1 and add some other options
function tiny_mce_remove_unused_formats_formatselect($init) {
$init['block_formats'] = 'Paragraph=p;Heading 2=h2;Heading 3=h3;Heading 4=h4;Heading 5=h5;Heading 6=h6';
return $init;
}
add_filter('tiny_mce_before_init', 'tiny_mce_remove_unused_formats_formatselect' );
@certainlyakey
certainlyakey / functions.php
Last active March 15, 2018 23:26
Hide visual editor on edit screens of specific pages in admin (Wordpress)
<?php
// hide support for certain admin "features" (metaboxes) for some pages
function hide_features() {
if ( isset($_GET['action']) && $_GET['action'] === 'edit' ) {
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'];
if( !isset( $post_id ) ) return;
$templated_pages_names = array(
// 'template-contact.php',
@certainlyakey
certainlyakey / functions.php
Last active March 15, 2018 23:17
Remove unnecessary sections from the theme customiser (Wordpress)
<?php
// Remove unnecessary sections from the theme customizer
function edit_customizer($wp_customize) {
$wp_customize->remove_section("colors");
$wp_customize->remove_section("custom_css");
// $wp_customize->remove_section("static_front_page");
}
add_action( "customize_register", "edit_customizer" );
@certainlyakey
certainlyakey / functions.php
Created March 15, 2018 19:53
A fix for Polylang language switcher links pointing at front page on post type archives of untranslated post types (Wordpress + Polylang)
function polylang_languageswitcher_untranslated_pts_archives_links_fix( $url, $slug ) {
if ( is_post_type_archive( array('event', 'career') ) ) {
$url = add_query_arg(
array(
'post_type' => get_post_type(),
),
pll_home_url( $slug )
);
}