Scripts and Actions for WordPress
Change the text set featured image in the admin panel
The code works great, I checked. Think, the method itself may be useful to someone, for example, when writing your own assembly WordPress and optimization of user experience “Usability”.
1 2 3 4 |
function custom_admin_post_thumbnail_html( $content ) { return $content = str_replace( __( 'Set featured image' ), __( 'Set default image' ), $content); } add_filter( 'admin_post_thumbnail_html', 'custom_admin_post_thumbnail_html' ); |
Creating a user right from the WordPress code
Attention user is created immediately, how do you paste the code in your theme's functions.php file and update the site itself. Code can be useful for plugin development.
Attention check the code is not on the current site, so as not to accidentally create extra users and not litter your site with extra accounts.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
function fb_wp_insert_user() { $user_data = array( 'ID' => '', 'user_pass' => wp_generate_password(), 'user_login' => 'dummy', 'user_nicename' => 'Dummy', 'user_url' => '', 'user_email' => 'dummy@example.com', 'display_name' => 'Dummy', 'nickname' => 'dummy', 'first_name' => 'Dummy', 'user_registered' => '2010-05-15 05:55:55', 'role' => get_option('default_role') // Use default role or another role, e.g. 'editor' ); $user_id = wp_insert_user( $user_data ); } add_action( 'admin_init', 'fb_wp_insert_user' ); |
Checking if the plugin is active or not in the plugin code, which you are developing.
1 2 3 4 5 |
<?php If (is_plugin_active('plugin-directory/plugin-file.php')) { //yes my plugin is active } ?> |
1 |
add_filter('user_can_richedit' , create_function('' , 'return false;') , 50); |
Making Empty Categories Display in WordPress Widgets
As you already know, widgets WordPress categories do not allow displaying empty categories. Adding this snippet to functions.php your topic WordPress will force the system to display empty categories.
1 2 3 4 5 |
add_filter( 'widget_categories_args', 'force_widget_cat_args' ); function force_widget_cat_args($cat_args) { $cat_args['hide_empty'] = 0; return $cat_args; } |
Removing the comments item from the admin bar
To remove a comment item from the admin bar, paste the code into the file functions.php your topic.
1 2 3 4 5 |
function remove_comments(){ global $wp_admin_bar; $wp_admin_bar->remove_menu('comments'); } add_action( 'wp_before_admin_bar_render', 'remove_comments' ); |
Move the author's metabox to the post block
Just a chic code to indicate the author of the publication of the article. In this case, you do not have to twist the screen to the very end.. Your author metabox will appear right above the publish button. For an action to work in WordPress need to add code, suggested below to your theme's functions.php file.
1 2 3 4 5 6 7 8 9 10 11 12 |
add_action( 'admin_menu', 'remove_author_metabox' ); add_action( 'post_submitbox_misc_actions', 'move_author_to_publish_metabox' ); function remove_author_metabox() { remove_meta_box( 'authordiv', 'post', 'normal' ); } function move_author_to_publish_metabox() { global $post_ID; $post = get_post( $post_ID ); echo '<div id="author" class="misc-pub-section" style="border-top-style:solid; border-top-width:1px; border-top-color:#EEEEEE; border-bottom-width:0px;">Author: '; post_author_meta_box( $post ); echo '</div>'; } |
From the category directly to the article if there is only one article in the category
In previous lessons I showed, how to do search redirect, if the result is the same, which is very convenient for users. Today I will show you how to make a redirect for categories and redirect the user directly to an article from the list of articles in the category if there is only one article in the selected category.
1 2 3 4 5 6 7 8 |
function redirect_to_post(){ global $wp_query; if( is_archive() && $wp_query->post_count == 1 ){ the_post(); $post_url = get_permalink(); wp_redirect( $post_url ); } } add_action('template_redirect', 'redirect_to_post'); |
/*
- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.