0

I created wordpress page template and i want to add this css code only in to inside of this template only.for the security concern should i escape?. can anyone help me to solve this?. here is the code i used.

<?php  $style = "<style type='text/css'> .post-related {position: relative; width: 21.333%!important;} </style>";

echo  $style  ;
?>
4
  • If its hard coded by you and it will never accept data from unknown sources, go for it. there are better ways to do it but from a security point, if you control 100% of the code there is no problem Jul 22 at 8:49
  • Hi, Thank you very much for the help.. really appreciate it.! quick question can i put direct <style> </style> without echo? in template? .. jut for knowledge .. thank you..
    – Gayal cham
    Jul 22 at 9:22
  • Sure, just don't put it inside the <?php ... ?> tag. I can post an answer if you like so you can have a visual idea of how to do it, only if you need =] Jul 22 at 9:24
  • Thank you very much.. yes if you can it would be great..! im new to WordPress template files. thank you ..!
    – Gayal cham
    Jul 22 at 9:31
0

A very basic template

I created a file named about.php in a pages folder in the root of my theme with this code.

You can do the same or change the location as you see fit, just dont put it inside a child folder that is in a child folder, wordpress can't read templates two levels deep it folder structure.

<?php defined('ABSPATH') || exit;

// Template name: About

// this gets the header.php file
get_header();
?>
<!-- Here we can do what ever we need -->
<style>
    .content .headline,
    .content .description {
        text-align: center;
    }

    .content .headline {
        margin: 0 0 20px;
        font-size: 2rem;
    }

    .content .description {
        max-width: 400px;
        margin: 0 auto;
    }
</style>

<div class="content">
    <h1 class="headline">About Us</h1>
    <p class="description">Lorem ipsum dolor sit amet consectetur adipisicing elit. Aspernatur repellat eius a beatae consectetur, et perferendis impedit molestias itaque esse optio repellendus sapiente iure debitis suscipit temporibus voluptas architecto animi.</p>
</div>
<?php
// this gets the footer.php file
get_footer();
?>
5
  • Dear Buttered_Toast..thank you very much for the help.. now i understand everything.. this is very helpful for beginners..! Really appreciate your time and help..!
    – Gayal cham
    Jul 22 at 9:48
  • Great! glad I could help, I would suggest reading about wordpress themes/child themes and wordpress theme templates to get a better understanding of how wordpress handles all this logic, also check wordpress wp_enqueue_scripts to understand how to load js/css files the wordpress way Jul 22 at 9:56
  • Sure I fill follow your instructions..! this is very helpful. again Thank you very much ..! :)
    – Gayal cham
    Jul 22 at 10:01
  • @Gayalcham Consider accepting this answer if you feel it helped you with your question =] Jul 22 at 10:01
  • Sure i did it..thank you very much..!
    – Gayal cham
    Jul 22 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.