Linking stylesheets from main site to Wordpress child theme - php

I have a website not running on Wordpress, but have installed Wordpress in the /blog sub directory. I'm trying to modify the chosen Wordpress theme to match the header of my website. I've managed to come relatively close, but by placing duplicate .css and .js files within the child theme.
What I want to do is give the proper path while enqueueing from functions.php - I'm just unfamiliar with .php and how to do so. Here's what I have:
<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'freelance-main', get_stylesheet_directory_uri() . '../../../freelancer.css' );
wp_enqueue_style( 'bootstrap-min', get_stylesheet_directory_uri() . '../../../bootstrap.min.css' );
wp_enqueue_style( 'bootstrap-main', get_stylesheet_directory_uri() . '../../../bootstrap.css' );
wp_enqueue_style( 'child-style',get_stylesheet_directory_uri() . '/style.css',
array('parent-style')
);
}
?>
From viewing the page source it's actually trying to load the "../" in the url so I know this isn't right, I just don't know how to type it properly. Here's the structure:
root
-mywebsite
--blog
---wp-content
----themes
-----child-theme
--css
---needed files
--js
---needed files
Like I said, if I duplicate the files and put them in the child-theme it works, but I don't think this is best practice.

Related

Css not enqueueing with get_template_directory_uri()

I'm having trouble calling my stylesheets using the enqueueing method on my functions.php file. I'm using the following
<?php
function load_stylesheets()
{
wp_register_style('style', get_template_directory_uri() .
'/style.css', array(), false, 'all');
wp_enqueue_syle('style');
}
add_action('wp_enqueue_scripts', 'load_stylesheets');
?>
I'm guessing that this is a hierarchy problem as I don't see any problem code wise. I have a theme folder with all of my php files which also contains the css file I'm attempting to reference
Spelling mistake
wp_enqueue_syle('style');
should be
wp_enqueue_style('style');
Forgot the 't' :)
Also while I am here...if you are registering then immediately enqueuing (with defaults) you can just do this as they can accept the same args:
wp_enqueue_style('main-style', get_template_directory_uri() . '/style.css');
If you are working on Child Theme you should use, get_stylesheet_directory_uri() instead of get_stylesheet_directory_uri()
// This will point to style.css in child theme
wp_enqueue_style( 'my_child_styles', get_stylesheet_directory_uri().'/style.css' );
// This will point to style.css in the parent theme
wp_enqueue_style( 'my_parent_styles', get_template_directory_uri().'/style.css' );

The Conflict of jQuery on WP (Admin Panel doesn't work correctly)

I'm using a custom Wordpress Theme for my blog. This theme is working good in the website but on the back, the widgets can't moving/automatically closing etc. I've tried to solve this problem with
define( 'CONCATENATE_SCRIPTS', false );
on WP-config. It solved the problem for widgets but right now, I can't upload featured image for posts. (It shows me an error about it couldn't upload, but it uploads and I can't see the library in wp-admin/post.php. I can see all images in wp-admin/upload.php
My functions.php looks like that:
function aax_scripts() {
// Styles
wp_enqueue_style( 'Bootstrap-4', get_template_directory_uri().'/bootstrap/4.1.1/css/bootstrap.min.css');
wp_enqueue_style( 'AAX-Style', get_stylesheet_uri() );
wp_enqueue_style( 'Google-Fonts', 'https://fonts.googleapis.com/css?family=Oswald|Roboto|Libre+Franklin');
wp_enqueue_style( 'Font-Awesome', get_template_directory_uri().'/fontawesome/fontawesome-free-5.2.0-web/css/all.css');
// Scripts
wp_enqueue_script("jquery");
wp_enqueue_script( 'Bootstrap-4', get_template_directory_uri() . '/bootstrap/4.1.1/js/bootstrap.min.js');
wp_enqueue_script( 'Popper', get_template_directory_uri() . '/js/popper.min.js');
};
add_action( 'wp_enqueue_scripts', 'aax_scripts' );
What should I do?
Thanks.
I found the solution. This problem is not about jQuery.
The source of problem is a commenting function in theme's function.php file.
if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
The function includes a global query and WP using queries everywhere. It was looking cool on page but it doesn't means it's a good code.
Be careful your functions. Don't be me.

Divi Child Theme Breaks Wordpress Customizer

I am having an issue with the wordpress customizer and Divi. Customizer works fine with just Divi activated, but when I activate a child theme the customizer suddenly stops working. It displays on the user facing side, but will not render in customizer.
I get this error from Chrome:
"bpmmarketing.com redirected you too many times."
So I of course made sure my functions file was kosher, which it is.
Here's that code (from elegant themes):
<?php
function my_theme_enqueue_styles() {
$parent_style = 'parent-style';
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
wp_get_theme()->get( 'Version' )
);
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>
I am seeing this error in the console:
load-scripts.php?c=1&load[]=jquery-core,jquery-migrate,jquery-ui-core,jquery-ui-widget,jquery-ui-mo…:3
GET
http://bpmmarketing.com/?customize_changeset_uuid=9610c2a0-37d1-4b5a-abd6-d…ccfb7c&customize_theme=BPM+Marketing&customize_messenger_channel=preview-0
net::ERR_TOO_MANY_REDIRECTS
We have the site protected right now, but please let me know if you need any other information.
Your theme folder might contain spaces, for example "Divi child". If so you must change it to "Divi-child" and problem solved.
If not you can set the permalinks to plain as a workaround, but this is not good for SEO.

WordPress: override multiple css files in child theme in the proper order

How can I enqueue more css files from the parent theme in the child theme and in which order?
Note: the previous method was to import the parent theme stylesheet using #import, but this is no longer best practice, because it uploads the stylesheet twice.
The correct method of enqueuing the parent theme stylesheet is to add a wp_enqueue_scripts action and use wp_enqueue_style() in the child theme's functions.php.
So, this is the correct PHP code to use:
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
But this uploads only style.css and all themes have multiple css files, so how can I enqueue all of them? And how can I keep the proper order of uploading files?
For example, how can I enqueue the file main.css from the path theme_parent_directory/css/main.css in addition to style.css?
I hope that my English is clear. :)
Thank you in advance!
<?php
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles',999 );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/css/main.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style )
);
}
?>

wordpress child theme: how to overwrite template .php files

I have a child theme setup in wordpress and the style.css and functions.php in the child theme are working correctly. I now want to overwrite other template .php files with the versions in the child theme. I can't seem to make these files overwrite the parent theme however.
child theme functions.php:
<?php
//enqueue styles
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles', 'overwrite' );
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
//overwrite template pages
function overwrite() {
wp_enqueue_script( get_template_directory_uri() . '/inc/structure/hooks.php' );
wp_enqueue_script( get_template_directory_uri() . '/inc/structure/header.php' );
}
I have a hooks.php and header.php in /child-theme/inc/structure/
For a child-theme you do not need to enqueue any template (PHP) files, simply add a PHP file to your child-theme with exactly the same name and path as the one you are trying to overwrite in your parent theme and it will naturally replace it.

Categories