WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Which is better, functions.php or style.css (6 posts)

  1. another-webmaster
    Member
    Posted 2 years ago #

    Is it better (faster/more stable) to use a CSS code or function for following?
    To create two columns I have a function as following (just part of full code shown here):
    (left column)
    $content = '<div style="width: 45%; margin-right: 5%; float: left; text-align: justify; ">' . $content . '</div>';
    (right column)
    $content = '<div style="width: 45%; float: left; text-align: justify;">' . $content . '</div><div style="clear: both;"></div>';
    Using it with a shortcode it works like a charm but it is still a function.
    I could also use CSS code itself and create div+class in style.css (I only edit in html mode. I never use crappy visual editor).

    Does it matter which way I use or is it prefer to use the style.css above functions.php?
    Looking forward to answers, thanks in advance.

  2. I would add a class to your function and put the styles in your CSS as it's always preferable to keep functionality and form separate.

    i.e.

    <div class="foo">
    
    .foo {
      width: 45%;
      margin-right: 5%;
      float: left;
      text-align: justify;
    }
  3. another-webmaster
    Member
    Posted 2 years ago #

    You are so right with that, absolutely maam! but (sorry no offence) still it is as a function call.
    Maybe I didn't explain what/how I meant the question above, sorry for that. To enlighten some by this sample;

    In a post/page we can do it 2 ways, the first way could be like this:
    (for left column):
    <div class="lcol"> the text here </div>
    (for right column):
    <div class="rcol"> the text here</div>
    And in style.css giving the correct codes for the classes, no shotcode is used this way.

    Second way can be done like this, clicking the created button (we did ourselfs, btn are lcol and rcol):
    [lcol]{txt here}[/lcol] and [rcol]{txt here}[/rcol]

    Using the shortcode methode is for our authors faster with same output results.

    But I actualy was/am curious if a plugin/function call needs more "load" from server than just the "regular" styling way by using "only" css code, as shown in the sample as above now.
    I ask that because our site (as it is now) has over 2/3k postings and I am a little afraid that plugins/function calls like these also will have a neg impact on server loads but maybe I am totally incorrect.

  4. Ah - thanks for clarifying. Unfortunately I don't know the answer to this one but hopefully someone else will chime in. I'll see if some other folks might know.

  5. Ron Rennick
    MultiSite Guru
    Posted 2 years ago #

    Putting it in your css reduces your server load because the browser will only load that css once (and keep it in cache).

    You can change your shortcode so that it outputs

    <div class="lcol"> the text here </div>

    instead of the inline styles.

  6. another-webmaster
    Member
    Posted 2 years ago #

    Thank you both for fast responding, will split up function and styling to where both belong :)

Topic Closed

This topic has been closed to new replies.

About this Topic