I found this script online which adds a menu item and a page with content from a php function.
However i cant seem to get the content to load from the admin-handleiding.php file.
.
wp-content/theme/functions.php
add_action( 'admin_menu', 'my_admin_menu' );
function my_admin_menu() {
add_menu_page( 'Website handleiding', 'Handleiding', 'manage_options', 'admin-handleiding.php', 'handleiding_admin_page', 'dashicons-media-document', 6 );
}
function handleiding_admin_page(){
?>
<div class="wrap">
<h2>Website handleiding</h2>
</div>
<?php
}
I hope anyone can help
Okay, im awake for too long. Forgot to include/require the page ^^
Related
I have a WooCOmmerce Login Page which I am customizing at the moment, by default the login and registration page are in one page. I had seperated the login and registration pages into 2 seperate forms right now. Currently I would like to put a link for the seperated registration page right below the "Forgot Password" link.
But my output is as follows :
I would like for it to appear as follows:
Below is the action hook I am using for my login page.
add_action( 'woocommerce_after_customer_login_form', 'register_link' );
function register_link() {
?>
<div class="woocommerce-register-link">
<p><?php _e( 'Register a new account here' ); ?></p>
</div>
<?php
}
Any help would be much appreciated.
This can be done in multiple ways:
You can edit the template myaccount/form-login.php to insert your code in the right location.
you can use Javascript/jQuery to insert your code in the right location, without editing any template:
// The jQuery Ajax request
add_action( 'wp_footer', 'wc_separated_login_form_js' );
function wc_separated_login_form_js() {
// Only my account for unlogged users
if( ! is_user_logged_in() && is_account_page() &&
'yes' === get_option('woocommerce_enable_myaccount_registration') ):
// Your button html to insert
$html = sprintf(
'<p class="woocommerce-Registerlink register-link">%s</p>',
home_url('/registration/'), // <== Here set your registration link
__( 'Register a new account here')
);
// jQuery
?>
<script type="text/javascript">
jQuery( function($){
$('p.lost_password').after('<?php echo $html; ?>');
});
</script>
<?php
endif;
}
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
I'm trying to add a reCAPTCHA to WooCommerce Checkout on WordPress. When I use the following snippet the captcha loads and works correctly:
add_action( 'woocommerce_review_order_before_payment', 'woocommerce_checkout_recaptcha_field' );
function woocommerce_checkout_recaptcha_field( ) {
echo '<div class="g-recaptcha" data-sitekey="XXXXXXXXXXXX"></div>';
}
However as soon as I move it next to the terms and conditions checkbox:
add_action( 'woocommerce_checkout_before_terms_and_conditions', 'woocommerce_checkout_recaptcha_field' );
function woocommerce_checkout_recaptcha_field( ) {
echo '<div class="g-recaptcha" data-sitekey="XXXXXXXXXXXX"></div>';
}
The captcha stops loading. I can see the captcha beginning to load as the page makes a gap for it but then after a split second it disappears again.
Anyone got any ideas?
Thanks
I'm new to wordpress plugin development & I want to make a plugin. So far I managed to add Menu in Dashboard. Now I want to add a submenu. Menu works when I click on it but submenu doesn't work. It shows this error, You do not have sufficient permissions to access this page. My code is below,
<?php
add_action( 'admin_menu', 'sms_dashmenu');
function sms_dashmenu() {
add_menu_page( 'sms_menu_page', 'SMS Demo','manage_options', __FILE__,'sms_plugin',plugins_url( '/Images/logo.png', __FILE__ ) );
add_submenu_page( __FILE__, 'AdminPanel','Admin', 'manage_options',__FILE__.'/menu1', sms_panel_admin);
}
function sms_plugin(){
echo 'Welcome to the business!';
}
function sms_panel_admin(){
?>
<h2>Admin Panel Design</h2>
<?php
}
?>
Is there something wrong in my code? I need a solution badly. Your help would be appreciated. Tnx.
The fourth parameter in add_menu_page is the menu slug of string type use anything unique you want, and the first parameter of add_submenu_page is the parent slug and that is what you entered for add_menu_page menu slug
add_menu_page( 'sms_menu_page', 'SMS Demo','manage_options', 'smsmenu','sms_plugin',plugins_url( '/Images/logo.png', __FILE__ ) );
add_submenu_page( 'smsmenu', 'AdminPanel','Admin', 'manage_options', 'smsadmin', 'sms_panel_admin');
Check add_menu_page and add_submenu_page
I am trying to develop multiple plugins to fill various needs I have in WordPress. I figured I would create a 'base' plugin, and then other plugins can be installed on top.
I have created a menu page in my base plugin using add_menu_page (all this is in my class obviously, variables replaced with strings for ease of reading)
private function __construct() {
add_action('admin_menu', array($this, 'add_group_page'));
}
public function add_group_page(){
add_menu_page('Group Plugins', 'Group Plugins', 'activate_plugins', 'group-plugins', array($this, 'group_page_callback'), '', 3.1415);
}
public function group_page_callback() { ?>
<div class="wrap">
<h2>Group Plugins</h2>
</div>
<?php
}
That works fine, my menu structure now has: (tags wrong on purpose, for readability of urls)
(Group Plugins)[admin.php?page=group-plugins]
In my second plugin, I try to call add_submenu_page:
private function __construct() {
add_action('admin_menu', array($this, 'add_groupforms_page'));
}
public function add_groupforms_page(){
add_submenu_page('group-plugins', 'Group Forms', 'Group Forms', 'manage_options', 'group-forms', array($this, 'groupforms_page_callback'));
}
public function groupforms_page_callback() { ?>
<div class="wrap">
<h2>Group Forms</h2>
</div>
<?php
}
Which seems like it has worked in adding the new submenu item. But the menu structure changes to:
(Group Plugins)[admin.php?page=**group-forms**]
--(Group Forms)[admin.php?page=**group-forms**]
So both links link to the new submenu page, and when I click on either of them, I just get a backend styled page that says You do not have sufficient permissions to access this page.
I can still access 'Group Plugins' original page if I change the slug in the url to 'group-plugins', but something clearly isn't right, and the only thing that really shows up when I google the error is people saying to check its hooked in the right place: admin_menu, which it is, because I have checked the docs so many times trying to figure this out.
You have to fire the submenu after the menu. This is done with the hook priority, when not declared defaults to 10.
The main menu is setup with default priority:
add_action('admin_menu', array($this, 'add_group_page'));
And the submenu has to be a lower priority:
add_action( 'admin_menu', array($this, 'add_groupforms_page'), 11 );
I recently got into WordPress plugin development and I would like to add a menu page (the links in the left hand side menu). Previous SO questions and the WordPress codex say that it's as simple as calling:
add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );
However when I try this in my plugin setup file it tells me that the function is undefined:
PHP Fatal error: Call to undefined function add_menu_page()
This seems like a very simple thing to do according to the documentation but I am totally baffled. Any help would be really appreciated :)
I don't know how your code looks but this is how I just tested and it worked:
add_action('admin_menu', 'my_menu');
function my_menu() {
add_menu_page('My Page Title', 'My Menu Title', 'manage_options', 'my-page-slug', 'my_function');
}
function my_function() {
echo 'Hello world!';
}
Take a look here http://codex.wordpress.org/Administration_Menus
You are getting this error message because either you have used the function add_menu_page outside any hook or hooked it too early.
The function add_menu_page gets capability as a third argument to determine whether or not the user has the required capability to access the menu so the function is only available when the user capability is populated therefore you should use the function in the admin_menu hook as following.
add_action( 'admin_menu', 'register_my_custom_menu_page' );
function register_my_custom_menu_page(){
add_menu_page( __( 'Custom Menu Title' ), 'custom menu', 'manage_options', 'custom-page-slug', 'my_custom_menu_page' );
}
function my_custom_menu_page() {
echo __( 'This is custom menu page.' );
}
See the following WordPress codex page for information about it.
http://codex.wordpress.org/Function_Reference/add_menu_page