Jump to content

How to call a CSS?


Decarn

Recommended Posts

In WordPress, you include style sheets with the wp_enqueue_style() function that you can call using the wp_enqueue_scripts hook.

function queueMyStyles(){
	wp_enqueue_style('subbranding',get_stylesheet_directory_uri()."/myStyle.css",'site-style');
}
add_action('wp_enqueue_scripts','queueMyStyles');
Link to comment
https://forums.phpfreaks.com/topic/292501-how-to-call-a-css/#findComment-1496736
Share on other sites

Hi,

 

Sorry if this is the code, how do I call alignleft in style.css for /images/default-image.jpg?

add_filter( 'genesis_pre_get_image', 'category_featured_image_fallback' );
function category_featured_image_fallback() {	
	if ( has_post_thumbnail()) :
	the_post_thumbnail( 'thumbnail', array( 'class' => 'alignleft' ) );

	elseif ( in_category( 'shares-derivatives' ) ) :
		echo '<img src="' . get_stylesheet_directory_uri() . '/images/default-image.jpg' . '" alt="Shares & Derivatives Left" />';
    
	elseif ( in_category( 'two' ) ) :
		echo '<img src="' . get_stylesheet_directory_uri() . '/images/category-two.png' . '" alt="Your Alt Text" />';		
    
	else: 
        echo '<img src="' . get_stylesheet_directory_uri() . '/images/default-image.png' . '" alt="No Category" />';
	endif;	
}
Link to comment
https://forums.phpfreaks.com/topic/292501-how-to-call-a-css/#findComment-1496764
Share on other sites

You just add "class='alignleft'" to the <img /> line. The only reason that the class is 'called' for the thumbnail is that the_post_thumbnail() is a template tag and by default outputs the source code, so the theme developer is passing the class name into the function call as one of the optional parameters.

Link to comment
https://forums.phpfreaks.com/topic/292501-how-to-call-a-css/#findComment-1496781
Share on other sites

I see that you're not too familiar with PHP. I suggest you learn it from the official website because that will help you much more. If you learn it from a tutorial, you won't get any where.

 

In addition, you're placing your edits in the wrong places.

echo '<img class="alignleft" src="' . get_stylesheet_directory_uri() . '/images/default-image.jpg" alt="Shares & Derivatives Left" />';

Take out all those double single quotes. You're placing them where they aren't suppose to and you're placing them where you don't have any PHP codes.

 

You need to learn the basics of HTML too if you're not sure where to put the double quotes.

Link to comment
https://forums.phpfreaks.com/topic/292501-how-to-call-a-css/#findComment-1496845
Share on other sites

I have to agree with LeJack on this one - taking some time to learn a little HTML, CSS, php, and WordPress is going to help a lot in this situation. The thing about WordPress is that it's great for end-users, but once you start digging into and modifying the code, it's kind of a nightmare from that perspective. The reliance on global functions and variables can make things difficult to follow and really isn't good modern coding, so you should have a decent grounding in php to know when and how to break both php's and WordPress's rules. And no offense, but if you don't know how to assign a class to a DOM element, you're going to be in over your head quickly. The nice thing is, it doesn't take a whole lot of time to learn the basics that you need to know. That being said, you do need to know those basics.

Link to comment
https://forums.phpfreaks.com/topic/292501-how-to-call-a-css/#findComment-1496928
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.