Renaming a default taxonomy field ('description') in WordPress - wordpress

I'd like to either utilize the description field in a custom taxonomy I'm building but rename it to bio, or remove description altogether and create the new field on my own.
Any idea what I need to do either of these?

What about this jQuery hack? Place it in functions.php of your theme or create a simple plugin:
function rename_category_description() {
global $current_screen;
if ( $current_screen->id == 'edit-category' ) { ?>
<script type="text/javascript">
jQuery('document').ready(function() {
jQuery("label[for='tag-description']").text("Bio");
});
</script>
<?php }
}
add_action('admin_head', 'rename_category_description');

Related

How to hide advanced custom fields(ACF) in the WP-admin UI?

Check the screenshot below; all I want to do is to hide certain ACF fields for custom users in the wordpress backend.
As of ACF 5.0.0 there is an easier way to do this without having to output CSS. If you use the acf/prepare_field hook and return false the field will not render.
<?php
function so37111468_hide_field( $field ) {
// hide the field if the current user is not able to save options within the admin
if ( ! current_user_can( 'manage_options' ) ) {
return false;
}
return $field;
}
add_filter( 'acf/prepare_field/key=MYFIELDKEY', 'so37111468_hide_field' );
?>
The documentation for that filter can be found here: https://www.advancedcustomfields.com/resources/acf-prepare_field/
If you mean to hide it with CSS, then you should insert custom CSS to admin footer area.
For example, you can add such kind of code to your theme's functions.php file:
add_action('admin_footer', 'my_admin_hide_cf');
function my_admin_hide_cf() {
$u=wp_get_current_user();
$user_roles = $u->roles;
if ($user_roles[0]=='CUSTOM_USER_ROLE_NAME'){
echo '
<style>
#acf-FIELD_SLUG_HERE {display:none}
</style>';
}
}
And of course you should replace FIELD_SLUG_HERE and CUSTOM_USER_ROLE_NAME values with correct ones.
F.e. #acf-FIELD_SLUG_HERE can be #acf-url, CUSTOM_USER_ROLE_NAME can be "contributor".

How do I generate custom title tag in wordpress manually?

Here's the sample code:
<title>Reviews <?php wp_title();?><?php echo " (".get_post_meta($post->ID, 'imdb_year', true).")"; ?></title>
And How do I create the wp_title() function above correctly?
This will change the title.
add_filter('pre_get_document_title', 'change_the_title');
function change_the_title() {
return 'The expected title';
}
So basically you can add extra logic inside it to change on specific pages, categories, post_types, etc..
Wordpress 4.4+: wp_title filter takes no effect on the `<title>` tag

Wordpress - Hide taxonomy fields in QuickEdit

after creating taxonomies for a custom post type, they all show up in QuickEdit. I'm trying to hide them to use the menu for other custom fields but don't know how to do it. Appreciate for any help.
Even better, when registering the taxonomy, you can now pass this to the register_taxonomy function, as shown here:
'show_in_quick_edit' => false
This seems to be working since Wordpress 4.2.
A bit late to the party, but for future reference, you can use a filter for this since Wordpress 4.2.0: quick_edit_show_taxonomy. Much cleaner than the javascript approach :)
add_filter('quick_edit_show_taxonomy', 'listing_remove_taxonomy_from_quick_edit', 10, 3);
function remove_taxonomy_from_quick_edit($show_in_quick_edit, $taxonomy_name, $post_type) {
if ('post_type' === $post_type) {
return false;
}
return $show_in_quick_edit;
}
Hope this will work
Try doing by javascript. (I use jquery).
jQuery(document).ready(function($){'use strict';
if ($('.post-type-custom').length) {
$('.taxonomy-checklist').prev().prev().hide(); // to hide title
$('.taxonomy-checklist').hide(); //to hide box
} });
add this code to a js file (lets say customadmin.js and assume its in the js folder that is in the theme folder) and enqueue the file on admin side:
if(!function_exists('addstyle_to_admin')):
function addstyle_to_admin() {
if(is_admin()){
wp_enqueue_script('myadminpanelscript',get_template_directory_uri() . '/js/customadmin.js',array('jquery'),false,false);
}
}
add_action('admin_enqueue_scripts','addstyle_to_admin');
endif;

How to add a button to a custom post type in Wordpress?

I have a "Products" custom post type. Normally, this custom post type have an "Add New" button. I want to add another button call "Update from Provider".
Currently, I have modify the Wordpress code (in "wordpress\wp-admin\includes\class-wp-list-table.php") to add that button. In this case, when I update Wordpress, my modified code will be deleted. Therefore, I need to move that button to my plug-in code.
In this case, please help me how to move that button to my plug-in code.
Well, if you opened the core file you saw that there's no action in it where we can hook.
Only a couple of filters. We can use the following:
add_filter( 'views_edit-movies', 'so_13813805_add_button_to_views' );
function so_13813805_add_button_to_views( $views )
{
$views['my-button'] = '<button id="update-from-provider" type="button" title="Update from Provider" style="margin:5px">Update from Provider</button>';
return $views;
}
It produces this:
To put it in an approximate position from where you'd like, use the following:
add_action( 'admin_head-edit.php', 'so_13813805_move_custom_button' );
function so_13813805_move_custom_button( )
{
global $current_screen;
// Not our post type, exit earlier
if( 'movies' != $current_screen->post_type )
return;
?>
<script type="text/javascript">
jQuery(document).ready( function($)
{
$('#update-from-provider').prependTo('span.displaying-num');
});
</script>
<?php
}
Which results in this:

Make Wordpress Pages's Titles readonly

I'm looking for a WP function that add the Read-only parameter to all Pages's Titles's input, that will make the Page's title unalterable.
Thanks a lot in advance.
This can be accomplished with some simple JavaScript/jQuery. Create a file called admin_title_disable.js, and queue it up within functions.php. For example:
functions.php:
wp_register_script('admin_title_disable', '/path/to/admin_title_disable.js');
function disableAdminTitle () {
wp_enqueue_script('admin_title_disable');
}
add_action('admin_enqueue_scripts', 'disableAdminTitle');
Now, in your js file:
jQuery(document).ready(function ($) {
$('#title').attr('disabled','disabled');
});
This will set both post and page title input fields with a disabled attribute. Hope this helps!
If you want to restrict this script to a particular admin page, wrap the add_action hook in a conditional that compares $_GET['page']. You can also take advantage of the $hook parameter that is available when using admin_enqueue_scripts to check for the page. See here.
Update::
WordPress makes it a little tricky to tell between post and page edit screens, but there is a hidden input that you can take advantage of. :) Here's an updated version of the jQuery that will only run on page edit screens:
jQuery(document).ready(function ($) {
//find the hidden post type input, and grab the value
if($('#post_type').val() === 'page'){
$('#title').attr('disabled','disabled');
}
});
No need to make a seperate js file. Adding this to your function.php will do the same that Matthew showed.
function admin_footer_hook(){
?>
<script type="text/javascript">
if(jQuery('#post_type').val() === 'post'){
jQuery('#title').prop('disabled', true);
}
</script>
<?php
}
add_action( 'admin_footer-post.php', 'admin_footer_hook' );
This Solution Will disable clicking on the post title and editing it using CSS. CSS targets post type "page" only. It has been tested on Gutenberg visual editor. Users Can still edit title from "Quick Edit".
Add this code to your functions.php file.
function disable_title_edit() {
if(!current_user_can('administrator')){
if( !current_user_can('administrator')){ ////Only allow Admin
echo '<style>.post-type-page .edit-post-visual-editor__post-title-wrapper{
pointer-events: none;
}</style>'; } }
}
add_action('admin_head', 'disable_title_edit', 100);

Resources