i need to make some blocks(widgets) like the same of WordPress dashboard widgets. that means if we dragged a widget to another position it wouldn't change after refreshing the page. is there any way for the same.?? i want some blocks or widgets (functioning like dashboard widgets) in my custom plugin. :)
I believe you need this:
function your_dashboard_widgets() {
global $wp_meta_boxes;
wp_add_dashboard_widget('custom_help_widget', 'Theme Support', 'your_widget_callback');
}
add_action('wp_dashboard_setup', 'your_dashboard_widgets');
function your_widget_callback() {
echo '<p>Welcome!</p>';
}
Related
I want to be able to remove the added widgets in my WordPress site
through functions.php like making the site clean without any plugins.
I found this code
// Delete All Existing Widgets
$sidebar_widgets = wp_get_sidebars_widgets();
foreach($sidebar_widgets['footer_first'] as $i => $widget) {
unset($sidebars_widgets['footer_first'][$i]);
}
wp_set_sidebars_widgets($sidebars_widgets);
but it doesn't seem right to work.
I searched and searched all over the internet but all I got is how to unRegister the whole widget which I'm already familiar with.
and I only want to remove it from the sidebar section.
Use below code hope for hiding sidebar
function disable_sidebar_custom( $sidebars_data )
{
if($sidebars_data['footer_first'] !=''){
$sidebars_data['footer_first'] = false;
}
return $sidebars_data;
}
add_filter( 'sidebars_widgets', 'disable_sidebar_custom' );
I have made a simple shortcode for my wordpress theme. I'm trying to align it on right-side above the corner of my page. Is it possible to insert shortcode function.php?
I want to place my Short-code in the top-bar (right side above the corner) so that it will work for each pages. Means if i click on any menu then the shortcode should have to work on that menu also.
Actually i'm new in web development. Please suggest me what shall i have to do so it will align where i want and should have work for each module.
You can use wordpress function for that. Please open the file on which you have to place shortcode. Like if you want to place it on header open header.php and add
<?php echo do_shortcode('[your_shortcode]'); ?>
where you want your shortcode content to appear
The best way is to find the top bar menu hook of your theme and then add this code (adapted for your needs) in your function.php child theme :
function my_shotcode_inside_top_bar ( $items, $args ) {
if (is_page() && $args->theme_location == 'secondary') {
$items .= '<li class="my-class">' . do_shortcode( "[my_shortcode]" ) . '</li>';
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'my_shotcode_inside_top_bar', 10, 2 );
is_page displays the shortcode in pages only but you can choose another condition or no condition at all.
secondary is the hook and it depends on your theme. You can normally find it in your theme header.php file.
A menu location selector should be added - that way some themes support multiple menus, and some are called "top" or custom added.
The shortcode could then contain a call to whatever a menu position is:
EG: [myshortcode menu="secondary"]
Didn't have enough points to add this as a comment.
I have a multisite WP with Buddypress and BP Multi Network.
The sites are being created automatically (data is coming from external system).
The problem is I want to show only the Activity tab in the menu and I want to rename it as well. I have created bp-custom.php and this is its content:
<?php
function bp_change_tabname() {
global $bp;
$bp->bp_nav['activity']['name'] = 'Duvar';
$bp->bp_nav['members'] = false;
}
add_action( 'bp_setup_nav', 'bp_change_tabname', 999 );
?>
It is not working though. It seems like the content of bp-custom is irrelevant.
Any ideas?
To remove a nav item from the navigation array you can use bp_core_remove_nav_item(). For example:
function my_remove_tabs() {
bp_core_remove_nav_item( $parent_id );
}
add_action( 'bp_setup_nav', 'my_remove_tabs' );
Where $parent_id is the slug of the parent navigation item.
To customise the tab labels, you could use a language file. See the Customising Labels, Messages and URLs article for more info on how and why.
First of all, I am new to wordpress and creating one application in wordpress. I am using one plugin, now in that plugin for particular role like student, teacher site goes into the admin panel.
Now, I want to customize admin panel look & feel for selected users like student & teacher. I have already tried "AG Custom Admin", but didn't satisfied completely. So, I want to make custom css.
Is there any way that I can is like,
if(is_admin())
{
// Use Default CSS
}
else
{
// My Custom CSS
}
If yes, then where can I use this condition? I am using wordpress 3.8
Any help will be very appericiable,
Thanks.
Checkout current_user_can() method:
http://codex.wordpress.org/Roles_and_Capabilities#Capabilities
That method could be used like this:
if ( current_user_can('moderate_comments') ) {
wp_enqueue_style( 'Teacher Styles', 'teacherStyles.css' );
}
else{
wp_enqueue_style( 'Default Styles', 'defaultStyles.css' );
}
I am using wordpress wp-admin to create the menu. It is under Appearance/menu.
I have a link that points to /members/ but what I really need is a link to /members/$logged_user...
For example /members/user_1 or /members/user_2.
How can I do that?
I dont know if it is important, but I am using buddypress plugin.
I have written a short script for adding dynamic buddypress links in wordpress menu. Hope it helps
I have added custom links in wordpress menu replacing username in link with --username--
example
http://website_name.com/members/--username--/messages/
then add this code in function.php
add_filter( 'nav_menu_link_attributes', 'menu_override', 10, 3 );
function menu_override( $atts, $item, $args ) {
$user = wp_get_current_user();
$newlink = str_replace("--username--", $user->user_login, $atts[href]);
$atts[href] = $newlink;
return $atts;
}
The default menu doesn't really have that option. But you can make your own walker function, searching for the keyword and replacing it with the current user.
See http://codex.wordpress.org/Function_Reference/wp_nav_menu#Using_a_Custom_Walker_Function
But it would probably be faster and more manageable to just place the link outside the menu call with some static html and the needed php.
You can use the BuddyPress Custom Profile Menu plugin to get close to this functionality, otherwise you will have to write custom code that uses actions/filters of wp_nav_menu().