Using "include" to put CSS into PHP file - php

I've looked at other questions/answers on this and none have seemed to work for me.
I have a PHP file that is loaded via AJAX. In that I have...
include('mods/math/include/geometry_styles.php');
The geometry_styles.php file basically looks like this...
<style>
.proof_ol_outdent {
position: relative;
margin-left: -18px;
}
</style>
The .proof_ol_outdent style is not getting recognized by Firebug (or used, for that matter). I also don't seem to get any PHP errors if I mess with the path of the include(), which seems strange. If I change the include to require though, everything breaks.
However, I think that my path is correct because I have a DEFINES file which I also load using include and it's path is include('mods/math/include/geometry_defines.php');. The defines get loaded and used properly using that path.
I have no idea why this isn't working. Any help would be appreciated.
UPDATE: To answer a couple comment questions....
1.) AJAX is loading table rows that fit into <tbody id="problem_area"> </tbody>.
2.) There is a file called ajax_loading.php which loads the content of a user-specified file by id number. Like this: ajax_loading.php?problem_id=34
3.) If I browse directly to ajax_loading.php?problem_id=34 I don't get the <style></style> tags should be present.

I've found an alternate way to get my CSS included. Therefore I'm closing this thread. My feeling is that since the data is being loaded via AJAX, that's causing some kind of problem. I don't know for sure though.
Thanks to all who commented and tried to help.

Related

php echo "<style>" posts css text

In one of my php functions I add some quite simple css. It worked very well until today. Actually the css is still doing his job, but in addition it prints in the middle of my layout whatever is written between the <style></style> tags - in my case it shows .element {display: none !important;} .
My code:
echo'<style>.element {display: none !important;}</style>';
Has there been any update to php or WP that doesn't allow this anymore? Is there any other way to do this?
Thanks a lot for your help!
I am not sure if it might change anything, but can you try print?
Also I think if <style> is not within <head></head> it will not work.
I found a working solution. Previously, I had a function in functions.php, which did some user type specific PHP and also CSS. Now I removed the CSS from functions.php and added it to header.php just before </head>.
The function is in two places now, which I wouldn't prefer, but it works very well.
Still a riddle to me is, how the echo "<style>...</style>"; used to work in functions.php for approx. the last 6 months or so and then suddenly yesterday created mentioned issue.
Btw, I also tried ?><style>...</style><?php and print "<style>...</style>";. All created the same issue. Again, the "<style>" was not shown on the browser, only whatever was inside. Also, the CSS worked. Whatever, statements I entered was interpreted as correct CSS, but in addition also shown as text right between the layout. Here is an example source code at the browser at my example page :
source code at browser
if you wanna to add a custom style to your WordPress theme (that probably you do not design it) its better to add it to custom styles from your admin area.

How to remove a part of an html code inside of a php?

I was trying to remove a "Search" button on the top left corner of a web site.
After searching here I found a tip here: Best way to find out which php file has generated an html line of code in WordPress
But still after installing the plugin I could not be able to locate the desired html line to simply erase it. Also tried using the css code above to temporary hide it.
.pesquisar {
display: none !important;
}
It did not work. Can somebody help me on how can I erase <button type="submit" value="Pesquisar">Pesquisar</button> from the html code?
I just found a great solution.
To anyone in need to find a specific part of an html code there is a plugin called String Locator: https://br.wordpress.org/plugins/string-locator/
It allows you to find across any file and regex. Ideally the plugin allows editing after identifying the file, but because I was using security plugins I got an error.
Desipte that the path of the located file is shown, so I was able to manually get to the located file and change it.
Another tip is if your file identified with the string plugin is located in a cache folder like it was in my case I recommend cleaning the cache using plugins such as autoptimize or wp fastest cache then do the search again.
When I did there was only one file that remains needing an edit, good luck!
You need to add the class "pesquisar" to the button, then your CSS will work:
<button class="pesquisar" type="submit" value="Pesquisar">Pesquisar</button>
In your CSS you use a class selector:
.pesquisar { // selects the items with class="pesquisar"
display: none !important;
}
You can add a css style= "display:none;" rule
<button type="submit" value="Pesquisar" style="display:none;">Pesquisar</button>
If you cannot find who generates this, maybe it's caused a wp plugin generates that content. Try to locate first who generates the button.
You can use this to hide it:
button[value="pesquisar"]{
display: none !important;
}

include() doesn't work when my page has GET param

I have a header.php file containing my DOCTYPE and all my links/scripts.
I use
<?php
// HTML DOCTYPE insert
include 'header.php';
?>
at top of all my pages to have only one header for everyone, and it works fine.
Now, I have another page that get from a database a summary of my products information. When someone click on the "read more" link:
<p>
read more...
</p>
another page opens with the full information displayed...
Actually that works...
BUT on my new page (display_product.php/id=[anynumber]) my included file doesn't work. So I have no nav bar, no scripts, no stylesheet. Only the text from my database.
AND the weird thing is that when I copy/paste the HTML of my generated display_product page and launch it on my browser, it works... O-o
So the generated code is good.
AND the second weird thing is that when I get rid of the /?id... my layout works fine (but I have no text anymore, of course)
Does one of you have an idea why this crazy things happens?
"Hi guys, Thanks very much Fred -ii this was it. it works perfectly. Thanks sergiodebcn for your concerne."
Since other answers were given and did not solve the actual problem, am posting my comment to an answer, in order to close the question.
Remove the slash from /?id
The slash is trying to instruct the server to probably find a folder after a filename, which technically looks like is what's happening here.
The ultimate solution for include and require functions with path issues, is to use the absolute filesystem path to the file that you want to include or require.
i.e you may say:
include("C:\\www\\app\\incs\\header.php");
Hint
To learn how to set the absolute path for include dynamically for your project, check the source code of two files of cakephp framework:
index.php
webroot/index.php

php include results in page being written in pre

I'm learning php, been trying to make a cms, but when I use an include for the header this results in the page appearing as if it were written in pre tags. There's no errors when I debug or anything. And I'm completely stumped. When I put the header back in without the include it renders just fine.
<?php include("..\includes\layouts\header.php"); ?>
That's the include I'm using.
I've tried using the full path name, tried it in different browsers and using :
include($_SERVER["DOCUMENT_ROOT"]
Check that you are closing your php tags, ending your strings with semi colons etc.. My guess is that your html is being sucked into the php code which freaks out and just dumps it.
Maybe try one of the validators such as http://phpcodechecker.com (I have not used this one so I cannot comment on it's effectiveness)
Edit: I am rereading your post and I think I understand what you are trying to say - your header contains the path to your css and when you put it in a separate php file the css doesn't work? So the first thing to do is determine if the issue with the php path or the css path inside the header.php file. Look at your source code to see if the header code is being included - if it is then play around with the css path - though including the header in a php file will not cause that css path to change.
I am guessing that your header is not included at all from your mention of paths. include() works from the loading file's location. The path it wants is a server path and not a url. The one that you have above: ../includes... means that you have an include folder at the same level as the loading file such as (assume index.php is the main file):
/includes/layouts/header.php
/somedirectory/index.php
The ../ means - drop down one directory then go up from there.
If your path is more like:
/includes/layouts/header.php
/index.php
Then the include would be:
include('./includes/layouts/header.php');
Let me know if that works - if it doesn't try to explain your directory structure.

AJAX, PHP Copied Files not Found on Return to Browser

I am using 'jQuery AJAX PHP' to do some '.jpg' file copying (approx 330kb per file). I copy files to a new directory location.
When I return to the HTML and use jQuery to add an IMG tag to a Table element, some of the files I have copied are shown as Not Found with 404 errors, but they are there.
I am wondering if it is a speed error. I tried to slow down the return from the PHP, by reading the directory where the files had been copied to, but that did not seem to help.
Am I right in thinking it is a speed problem and does anyone have an idea as to how I may overcome this problem, because only by displaying the copied file, can I be certain it has been copied.
Sometimes I have the same problem with not loading the images. If you are going to use jQuery I will recommend that you put your script (which loads the images) in
$(document).ready(function() {
// put all your jQuery goodness in here.
});
The fact is that your DOM object is not ready when you want to show or make operation with it.
Don't forget to call
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
in the head of your HTML.
Having tried various options suggested here and some others, I researched, I decided to try putting the display of the images in a different function from the AJAX/PHP. In other words instead of processing the images in the result function of the AJAX call, I just passed the results from the success function to another function.
This seems to have cured my not-found displays.
This may be a coincidence, with something else going on, because I am very poor in the knowledge of the flow of the DOM.

Categories