We would like to create a custom button in the wordpress dashboard,
We want this button to hold our pages we create for clients,
Because I want to keep the pages section separate from our "Client" pages
i hope this makes sense
It's really quite straight forward, just takes a bit of getting used to.
You ideally need to follow the docs:
https://codex.wordpress.org/Adding_Administration_Menus
https://developer.wordpress.org/reference/functions/add_menu_page/
This will guide you in how to set up an admin menu.
<?php add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); ?>
Will be the code you call when creating the admin sidebar menu item, however, there are more functions for create sub menu pages under it etc.
What I think you are looking for though, is a Custom Post Type for your clients...
https://codex.wordpress.org/Post_Types
function create_post_type() {
register_post_type( 'client_posttype',
array(
'labels' => array(
'name' => __( 'Clients' ),
'singular_name' => __( 'Client' )
),
'public' => true,
'has_archive' => true,
)
);
}
add_action( 'init', 'create_post_type' );
Something similar to above will get you started.
If it's all a bit much, you can generate CPT code:
https://generatewp.com/post-type/
Then have a look at the generated code to work out what it is that you would have coded yourself.
Test this :)
class options_page {
function __construct() {
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
}
function admin_menu() {
add_menu_page( 'Clients', 'Clients Page', 'edit_posts', 'clients_page', 'my_clients', '', 24);
}
function settings_page() {
echo 'This is the page content';
}
}
new options_page;
Related
Need a solution to remove the "Title" and "Add new" button from a post type without jQuery.
You can disable the add new capabilities while passing the parameter in the register post type.
The parameter is :
create_posts' => false
Assuming you have the code like below :
$args = array(
'label' => __( 'Custom Post Type', 'text_domain' ),
'capabilities' => array(
'create_posts' => false
)
);
register_post_type( 'custom_post_type', $args );
In order to remove the title I'm not sure if that is possible,
one solutions would be hiding using css
Best way to remove the title is to use the function remove_post_type_support().
remove_post_type_support('custom_post_type', 'title');
You can add this to your functions.php file by calling it via the init hook.
add_action( 'init', 'remove_custom_post_support' );
function remove_custom_post_support() {
remove_post_type_support( 'custom_post_type', 'title' );
}
i have created a custom taxonomy named 'singer' using pods plugin and inside that plugin i have defined a label named 'details'. what i want to do is to generate a short code in which returns that details. i have searched my way through lots of documentation, but could not find one.image showing the custom field i have added inside the taxonomy
Thanks for helping!
Do you need it to be that complicated? (Meaning, do you need a plugin?)
Register a new taxonomy in your functions "singer":
function taxonomies_init() {
// create a new taxonomy
register_taxonomy(
'singer',
'post',
array(
'label' => __( 'Singer' ),
'rewrite' => array( 'slug' => 'singer' ),
)
);
}
add_action( 'init', 'taxonomies_init' );
Register the shortcode:
function showtax_func( $atts ) {
if (is_single()) {
$a = shortcode_atts( array(
'tax' => '',
), $atts );
$termname = get_the_terms(get_the_ID(),$a['tax'])[0]->name;
return $termname;
}
}
add_shortcode( 'show_tax', 'showtax_func' );
Use the shortcode like this: [show_tax tax="singer"]
You can add more taxonomies by expanding the first function by duplicating the register_taxonomy() function. And get any taxonomy with the shortcode by just changing the value of the taxonomy name.
I'm trying to figure out a way for members on my Wordpress (Buddypress) site to pick their "favorite movies, books, etc."
It would be nice if, instead of members simply typing a list of these things, they could select from books already in the system, and add more as the please in the future.
I'm hoping that there is an easy answer to this, such as a plugin that I can use, or, at least, modify. Does anyone know of anything that I can look into?
Your title asks how to add a user profile field. Here is the code to add as many fields as you like. Once you add the field, you can easily place additional inputs or options on the custom tab page for users to enter their own favorites.
function my_test_setup_nav() {
global $bp;
$parent_slug = ‘test’;
$child_slug = ‘test_sub’;
//name, slug, screen, position, default subnav
bp_core_new_nav_item( array(‘name’ => __( ‘Test’ ),’slug’ => $parent_slug,’screen_function’ => ‘my_profile_page_function_to_show_screen’,'position’ => 40,’default_subnav_slug’ => $child_slug ) );
/* Add the subnav items to the profile */
// name, slug, parent_url, parent slug, screen function
bp_core_new_subnav_item( array( ‘name’ => __( ‘Home’ ), ‘slug’ => $child_slug, ‘parent_url’ => $bp->loggedin_user->domain . $parent_slug.’/', ‘parent_slug’ => $parent_slug, ‘screen_function’ => ‘my_profile_page_function_to_show_screen’ ) );
bp_core_new_subnav_item( array( ‘name’ => __( ‘Random Page’ ), ‘slug’ => ‘random’, ‘parent_url’ => $bp->loggedin_user->domain . $parent_slug.’/', ‘parent_slug’ => $parent_slug, ‘screen_function’ => ‘my_profile_page_function_to_show_screen234′ ) );
}
function my_profile_page_function_to_show_screen() {
//add title and content here – last is to call the members plugin.php template
add_action( ‘bp_template_title’, ‘my_profile_page_function_to_show_screen_title’ );
add_action( ‘bp_template_content’, ‘my_profile_page_function_to_show_screen_content’ );
bp_core_load_template( apply_filters( ‘bp_core_template_plugin’, ‘members/single/plugins’ ) );
}
function my_profile_page_function_to_show_screen_title() {
echo ‘wptaskforce title’;
}
function my_profile_page_function_to_show_screen_content() {
echo ‘wptaskforce content’;
}
//random page content:
function my_profile_page_function_to_show_screen234() {
//add content here – last is to call the members plugin.php template
add_action( ‘bp_template_content’, ‘my_profile_page_function_to_show_screen234_content’ );
bp_core_load_template( apply_filters( ‘bp_core_template_plugin’, ‘members/single/plugins’ ) );
}
function my_profile_page_function_to_show_screen234_content() {
echo ‘This is a random page.’;
}
add_action( ‘bp_setup_nav’, ‘my_test_setup_nav’ );
I am trying the following syntax to add menu-item on dashboard:
<?php add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); ?>
But, I am confused where to add this code.
Whether to add it in my theme's functions.php or my plugin's functions.php ?
Or any other way to add custom menu-item on the dashboard of the wordpress logged in as admin ?
I want to add custom menu item like the following image:
What you see in the screenshot is the screen of a Custom Post Type. In the documentation you will find an example code on how to add such a screen.
About where to place the code - it depends. Do you want to be able to use this Custom Post Type in other themes, or you will only need it in this theme?
If you want to use it in other themes as well, put the code in your plugin's code.
If you want to use it only in this theme, put it in your theme's functions.php.
And in case you still want to add a custom menu page, here you will find examples on what is the proper way to use this function. What you should note, is that the call to add_menu_page() should be done inside a function that is run on the admin_menu action.
Here's an example working code with WP 3.4.2
function register_custom_menu_page() {
add_menu_page('custom menu title', 'custom menu', 'add_users', 'custompage', '_custom_menu_page', null, 6);
}
add_action('admin_menu', 'register_custom_menu_page');
function _custom_menu_page(){
echo "Admin Page Test";
}
This is a perfect answer.
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'acme_product',
array(
'labels' => array(
'name' => __( 'Products' ),
'singular_name' => __( 'Product' )
),
'public' => true,
'has_archive' => true,
)
);
}
Im looking to add an action for each of the custom post types registered on my WordPress site (when a custom post type is published).
Now I could just manually add one for each of the types I have like:
add_action( 'publish_book', 'function_title_to_call' );
add_action( 'publish_movie', 'function_title_to_call' );
...
But I wanted to ask if there is a way it could be done so its all automated?
I tried the following without luck:
$arguments = array(
'public' => true,
'_builtin' => false
);
$all_post_types = get_post_types( $arguments, 'names', 'and' );
foreach ( $all_post_types as $one_post_type ) {
add_action( 'publish_' . $one_post_type, 'function_title_to_call' );
}
Any suggestions?