- This topic has 9 replies, 3 voices, and was last updated 5 years, 4 months ago by
Elvin.
-
AuthorPosts
-
December 14, 2020 at 3:01 pm #1580700
Randy
I’ve dug around the documentation and can’t seem to find how to make this one work.
I have javascript running in an Element with the hook generate_after_slidout_navigation
The particular part of javascript just gets ran on some pages based on a url parameter being present and page containing a certain div. All other style changes I’m running in that codeblock work fine, but not this one:
document.querySelector(“#content”).style.paddingTop = “0 !important”;
How can I get rid of the top padding in this limited circumstance?
December 14, 2020 at 4:39 pm #1580767Elvin
StaffCustomer SupportHi,
Can you link us to the page in question?
Also, can you indicate which part of the page you’re trying to remove?
You can provide the site details on the private information text field. Thank you. 🙂
December 14, 2020 at 5:39 pm #1580792Randy
Hi Elvin,
Thanks for the help!
See private info box for url detailsDecember 14, 2020 at 6:03 pm #1580802Elvin
StaffCustomer Supporthttps://share.getcloudapp.com/rRu0b6RR
To clarify further: Are you trying to reduce the space on the red box or the green box?#contentpadding-top: 0 !important;adjusts the space on the green box.div#content{ padding-top: 0 !important; }literally does the same thing as your script.
Devtool demo here – https://share.getcloudapp.com/E0u4jqwkIf you’re trying to reduce the space on the red box, it’s added by a div that contains a google ad.
.rlmtopaddivhas a fixedheight: 280px;. Adjust it to your preference.December 15, 2020 at 6:09 am #1581401Randy
Thanks Elvin.
div#content{ padding-top: 0 !important; } is basically what I am trying to do, but the issue I am having is that I only want to conditionally apply that css when a url parameter is present on the page, say &myparam=myvalue
Any thoughts on how I would apply that css conditionally based on a url parameter? (e.g. sometimes the css will be applied on Page A, and sometimes it will not be applied on Page A — it all depends on the url parameter)
December 15, 2020 at 12:41 pm #1582022Tom
Lead DeveloperLead DeveloperHow are you currently trying to output it?
You should just be able to do this:
add_action( 'wp_head', function() { // your conditions here.. ?> <style>.your-css {...}</style> <?php } );December 15, 2020 at 12:57 pm #1582037Randy
Nice! That did the trick, thanks Tom!!
Btw, is there any difference between:
?> <style>div#content{ padding-top: 0 !important; }</style> <?phpand
echo '<style>div#content{ padding-top: 0 !important; }</style>';when putting it into an add_action(‘wp_head’ function?
December 15, 2020 at 4:02 pm #1582162Elvin
StaffCustomer SupportThese 2 basically does the same thing but:
?> <style>div#content{ padding-top: 0 !important; }</style> <?phpThis one is preferred/better practice because it lessens the strain to the server as PHP doesn’t have to execute it as it is added directly as a static HTML tag. Ideally, only the logic part is left for PHP. All static contents should be left outside of it.
Meanwhile, this: echo
'<style>div#content{ padding-top: 0 !important; }</style>';passes the text string to be processed. It adds extra steps and uses unnecessary processing power from the server.Note: In real world scenario, these two will barely have noticeable performance difference. But of course, its good to know what the best practice is as multiple use of bad practice can accumulate and slow down the server.
December 15, 2020 at 4:46 pm #1582204Randy
Awesome Elvin! Really helpful answer. I appreciate it!
December 15, 2020 at 4:50 pm #1582210Elvin
StaffCustomer SupportAwesome Elvin! Really helpful answer. I appreciate it!
No problem. Glad to be of any help. 😀
-
AuthorPosts
- You must be logged in to reply to this topic.