I need to remove the Master Slider menu item from the wordpress admin menu. I have already tried the below but with no luck.
function edit_admin_menus() {
remove_menu_page('master-sliders');
}
add_action( 'admin_menu', 'edit_admin_menus' );
This should work for you. I tried it on my end and it works with no problems:
function sb_remove_admin_menus(){
if ( function_exists('masterslider') ) { ?>
<style type="text/css">
#toplevel_page_master-slider {
display: none;
}
</style>
<?php }
}
add_action('admin_menu', 'sb_remove_admin_menus');
See if that resolves.
function sb_remove_admin_menus(){
if ( current_user_can('editor') ) { ?>
<style type="text/css">
#toplevel_page_master-slider {
display: none;
}
</style>
<?php }
}
add_action('admin_menu', 'sb_remove_admin_menus');
Related
Trying to hide some elements "actions" from the "Add Media" window.
the thing is, I need to hide those actions in a specific post type
Tried the following snippet, of course not working
<?php
add_action( 'wp_head', function () { ?>
<style>
.media-menu-item #menu-item-featured-image {
display: none;
}
</style>
<?php } );
The only mistake is that the id "menu-item-featured-image" is not a child for the class "media-menu-item", but it is the same element
so just delete the space between ".media-menu-item" and "#menu-item-featured-image"
.media-menu-item#menu-item-featured-image {
display: none;
}
I created a plugin for WordPress. It opens a dialog box with an input field to fill, and then it creates a div with the contents of the field. Once the div was created in the editor, I would like to be able to doubleclick on this div and open the dialog box again.
How should I do it ?
Here, my PHP FILE :
<?php
/*
Plugin Name: my Plugin
*/
?>
<?php
function add_myItems(){
?>
<!-- the Dialog Box -->
<div id="myDialog">
<style type="text/css">
#myDialog {
display: none; /* hidden by default */
position: fixed;
z-index: 100; /* Sit on top */
width: 200px;
height: 200px;
}
</style>
<input id="myData" value="" />
OK
</div>
<!-- the WP button -->
Add DIV
<?php
}
function add_myJS() {
wp_enqueue_script('myJS', '/wp-content/plugins/my/script.js', array('jquery'), '1.0', true);
}
add_action('wp_enqueue_media', 'add_myJS');
add_action('media_buttons', 'add_myItems');
?>
...and Here, my JS FILE :
$('#myButton').click(function () {
$('#myDialog').show();
});
$('#myOK').click( function (){
var data = $('#myData').val();
var result ='<div class="myResult">' + data + '</div>';
wp.media.editor.insert(result); /* the WordPress function */
$('#myDialog').hide();
});
Thank you for your help. Nicolas.
Is there a way to change the style of something from display none to display block after a form has been submitted? I'm checking if the form has been submitted:
if(isset($_POST['submit'])){
I'm guessing it goes somewhere after here..?
I've tried this but no joy...
echo '<style type="text/css">
.login {
display: block;
} </style>';
thanks
You should probably define a style for hidden, and then add/remove that class from the parent element.
So in css:
<style type="text/css">
hidden{
display:none;
}
</style>
Then in your code something like:
$submitted = isset($_POST['submit']);
And when you render your form:
<div class="<?=($submitted)?'':'hidden'; ?>">
<form...
</div>
Alternatively, just don't render the form at all:
<?if(!$submitted){?>
<form...
<?}?>
I would tell you to add on your <form> an onsubmit:
<form onsubmit="DisplayLogin()">
And elsewhere some JS
<script>
function DisplayLogin(){
$('.login').css('display','block'); //using jquery
}
</script>
I think the piece of jQuery below should work for you, but it's very difficult because you didn't include a lot of code. Replace button with the button's id or class.
$('.button').click(function() {
$('.login').css('display', 'block');
});
JSFIDDLE
You can do something like this:
if(isset($_POST['submit'])){
<!--here you close the php tag-->
<style type="text/css">
.login {
display: block;
}
</style>
<!--here you open the php tag-->
}
i have a code:
<body <?php if( in_category( 11446 ) ) { echo "style=\"background-image: url('my-background-url-of-image');background-repeat:repeat;\" onclick=\"window.open('http://www.domain.com');\""; } ?> >
This code works only until page loads fully than something happens and it doesn't work i assume from inspect element that onclick function changes and i'm failing to find what part tricks that.
What this code does is it sets unique body background that are in specific category and background is clickable.
But because of some javascript error it doesn't work when page loads full so maybe somebody could explain me how to remove attr on Javascript and than add my with domain i want. Or maybe give example how to do alternative code just with href.
Thank you.
I'm assuming you are building a Wordpress template and the background image to be used is based upon the category of a Wordpress post.
This uses no Javascript. Instead, what it does is create the CSS declaration block inside the head tag of the HTML5 document on the fly. It does no inline CSS for the body tag.
<?php
// ====================================================
// Solution #1
// Background Image Only
// ====================================================
function GetThisWordpressPostCategory() {
// Do post category to filename mapping here
return("cars");
}
function in_category() {
// Just a dummy to simulate Wordpress in_category call
return(true);
}
function BodyBackground($category) {
$bodyCss = "";
if (in_category($category)) {
$bodyCss =<<<CSS
<style type="text/css">
body {
background-image: url('{$category}.jpg');
}
</style>
CSS;
}
return($bodyCss);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Category background</title>
<?php
$category = GetThisWordpressPostCategory();
echo BodyBackground($category);
?>
</head>
<body>
</body>
</html>
<?php
// ====================================================
// Solution: 2
// Clickable div spanning viewport
// ====================================================
function GetThisWordpressPostCategory() {
// Do post category to filename mapping here
return("cars");
}
function in_category() {
// Just a dummy to simulate Wordpress in_category call
return(true);
}
function PageCss($category) {
$pageCss = "";
if (in_category($category)) {
$pageCss =<<<CSS
<style type="text/css">
html, body, #page {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
background-image: url('{$category}.jpg');
}
#page-anchor {
display: block;
width: 100%;
height: 100%;
}
</style>
CSS;
}
return($pageCss);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Category background</title>
<?php echo PageCss(GetThisWordpressPostCategory()); ?>
</head>
<body>
<div id="page">
<a id="page-anchor" href="http://www.google.com"></a>
</div>
</body>
</html>
I am trying to echo a CSS style in php. basically I want to make a Div visible.
the Div's visibility is set to hidden in the css stylesheet and i need to make it visible in an else statement in php.
I am using this code:
<?php
} else {
echo '<style type="text/css">
#apDiv1 {
visibility:visible;
}
</style>';
}
?>
but that doesn't work! it doesn't make the Div visible. I tried it this way as a test and this way worked and it echo-ed hello world:
<?php
} else {
echo 'hello world';
}
?>
so is there any other way to do this? am I doing anything wrong?
You can also try like
<?php
} else {
?>
<style type="text/css">
#apDiv1 {
visibility:visible;
}
</style>
<?php
}
?>
Or directly give the div style like
<?php
} else {
?>
<div id="appDiv1" style="visibility:visible"></div>
<?php }
?>
Even you can put !important if any other styles are applied on that div.
try visibility: visible !important;, or display: block.
You can use javascript instead of css
<script>
document.getElementById('apDiv1').style.visibility = 'visible';
</script>
Do directly on the div:
<div id="apDiv1" <?php if(/* Your condition */){ /* Do something */ }else{ echo 'style="visibility:visible;"';} ?>></div>