0

I'm loading custom css stylesheet in my child theme 'functions.php' using this code

if (ICL_LANGUAGE_CODE == 'ar') { ?>
<link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri() . '/css/rtl.css' ?>" type="text/css">

When doing so, the media library can't be loaded, it just stick like this image:

enter image description here

Just a loading spinner with no result, even uploading files is corrupted. When removing the code, everything works perfectly.

Any ideas?


3 Answers 3

2

If you are echoing this code straight from functions.php it would output way before anything else. It is too early in the load process.

In most cases enqueue API functions should be used to output assets.

Outside of that it is impossible to guess what precisely might it be breaking and how. Examining browser console for errors and such might net some information to go on.

0
0

Correct way to add custom CSS file to your theme is different. You need to add function like this to your functions.php. Have on mind path to file can be different in your case.

function include_css()
{
    wp_enqueue_style( 'rtl', get_stylesheet_directory_uri() . '/css/rtl.css' );
}
add_action( 'wp_enqueue_scripts', 'include_css' );
0

In addition to the problems pointed out in the other answers, in the posted code, you're missing the closing bracket }. If this is the exact code you're using, then when the PHP interpreter comes to this piece of malformed code, it will unceremoniously die.

PHP if constructs can be formed in the following ways:

With brackets surrounding 1 or more lines of instructions:

if( $something ) {
  do_something();
}

An alternate format that will work with multiple lines:

if( $something ) :
  do_something();
endif;

Another alternate format that only works with on line of instruction

if( $something )
  do_somthing();
1
  • I just missed it when I copied the code. Commented May 7, 2017 at 6:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.