Hide specifics elements from "Add media" in WP - php

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;
}

Related

Wordpress : Re-Edit Content with DoubleClick in the editor

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.

Active class appended on <li> with Jquery not working on page load

I have set an active class on a dynamically created Wordpress navigational menu using this Jquery:
$(document).ready(function () {
$('.left-nav ul > li').click(function (e) {
e.preventDefault();
$('.left-nav ul > li').removeClass('active');
$(this).addClass('active');
});
});
CSS:
.left-nav ul li a {
color:#4D9120;
display:block;
}
.left-nav ul li:hover a {
color:#fff;
}
.left-nav ul li:hover {
background:#4D9120;
}
.left-nav .active{
background-color:#FF0000 !important;
}
.left-nav .active a{
color:#fff !important;
}
HTML/PHP
<ul>
<?php wp_nav_menu(array('theme_location'=>'sidemenu','container'=>'','menu_id' => '','fallback_cb'=> false)); ?>
</ul>
This is the HTML final output which are generated dynamically:
<div class="col-xs-3 left-nav">
<ul>
<li>Tutoring</li>
<li>Consultancy</li>
<li>Summer Camp/School</li>
<li>University Applications</li>
<li>Job Placements & Intenships</li>
</ul>
</div>
The active class is applied on clicking on any of the menu link but pages don't load. But when I removed e.preventDefault();the pages load but the active class is not applied anymore.
I would have loved to paste the website url but I'm currently working on a local server. Any help would be appreciated.
The current-menu-item class should be added to the active menu item by wp_nav_menu automatically. Get rid of the Javascript, and try adding this to your CSS:
.left-nav ul li.current-menu-item { background-color:#FF0000 !important; }
.left-nav ul li.current-menu-item a { color:#fff !important; }
See the documentation here.
here what is happening -
when you use "e.preventDefault();" for click event of a link you are actually stopping it from carrying out its default task which is - "loading a link on clicking",yet the javascript is carried out so your "active class" is applied on clicking but the link doesn't work and page doesn't load.
when you remove "e.preventDefault(); the link does work it loads the page its linked to but active class won't be applied because its totally a new page which is loaded which has nothing to do with javascript on your previous page from where it is loaded"..
hope this helps in solving your problem..

Remove master slider admin menu item from wordpress

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');

How style DIV when the id inclue strings in php?

How to use CSS or jQuery to style my background-color in DIV when the id inclue strings in php?
My code is:
<div id='result_'.$item_id.'>item</div>
You can attach a class to your div and use a jquery selector to get your div(by id or class) and change its css properties using .css(). Also I think you want to change the background after clicking on a specific div, so you need to attach also a click handler, extract its id and then change its background color.
<div class="my_class" id='result_'.$item_id.'>item</div>
$(".my_class").click(function(event){
var clicked_id_item = $(event.target).attr("id").split("_").pop();
$("#result_"+clicked_id_item).css('background-color','black')
})
If you can just add a class to your div, you can style it with css:
<div class="my-class" id='result_'.$item_id.'>item</div>
css:
.my-class {
background-color: red;
}
Or if you want to wrap your divs with a .wrapper, your css could be something like:
.wrapper > div {
background-color: red;
}
edit
I can see from your other comments that you are asking about the background-color changing when you click on the div. Although that was not made clear in your question, you could do that like this: (Building on my previous example)
.my-class.active {
background-color: blue;
}
Add some jquery:
$(".my-class").click(function(){
$(this).siblings(".active").removeClass("active"); // Maybe you could use .end() to keep the chain going
$(this).addClass("active");
});
You can use the attribute selector on the attribute id !
[id] matches every element with attribute "id".
[id=blah] is an equivalent to the selector #blah (every element with id="blah").
And [id^=blah] matches every element whose "id" attribute begins with blah.
[id^=result_] {
background: hotpink;
color: #fff;
}
div { margin: .2em; padding: .2em; }
<div id="result_blablah">#result_blablah</div>
<div id="result_hello">#result_hello</div>
<div id="nanana">#nanana</div>
<div class="plop">.plop</div>

How do I use PHP to build a website menu with dynamic highlighting?

I need to change color of selected menu whenever that page is active and it should stay until another menu is clicked.I have used jquery like
$('.navigation ul li a').click(function(){
$(this).css({"background-color":"#ffffff"});
$('.navigation ul li a').css({"background":"transparent"});
});
But it works only for the click function only.I need it to be active till i move to another menu .plz help!!!
PHP Only
Let us assume that your website has the following menu:
Home
Pistols
Rifles
At the top of the Home HTML page, insert:
<?php $this_page = "Home"; ?>
At the top of the Pistols HTML page, insert:
<?php $this_page = "Pistols"; ?>
At the top of the Rifles HTML page, insert:
<?php $this_page = "Rifles"; ?>
In your css-file, add an id, with the accompanying format, for the menu item whose page is the one displayed in the browser. Call this id #cur_item, for example.
Edit your navigation HTML to look like this:
<ul class="navigation">
<li <?php if ($this_page == "Home"):?> id="cur_item" <?php endif; ?> >
Home
</li>
<li <?php if ($this_page == "Pistols"):?> id="cur_item" <?php endif; ?> >
Pistols
</li>
<li <?php if ($this_page == "Rifles"):?> id="cur_item" <?php endif; ?> >
Rifles
</li>
</ul>
You don't need to use any jQuery, just CSS.
give your body tag and id for the page i.e. body id="contact"
give each menu link a class that matches the body id
Write the CSS for your active links:
'
body#home .navigation ul li a.home,
body#services .navigation ul li a.services,
body#contact .navigation ul li a.contact {
background-color: #ffffff
}
'
You need to use css a:active tag for this
$('.navigation ul li a').click(function () {
$('.navigation ul li a').each(function () { // loop through all links
if ($(this).hasClass('active')) $(this).removeClass('active'); // remove className 'active' from any link
});
$(this).addClass('active'); // className active to current link
});
CSS
.navigation ul li a {
background: transparent;
}
.navigation ul li a.active {
background-color: #ffffff;
}

Categories