I want the modified child theme site-banner1.css stylesheet to load after the parent theme so it overwrites the parent file with the changes. I am using the enqueue array() to try and push site-banner1.css to the end of the queue by inputting the last style id (CSS from a plugin) into the array function. Here is the code from functions.php:
<?php
if ( !defined( 'ABSPATH' ) ) exit;
if ( !function_exists( 'chld_thm_cfg_parent_css' ) ):
function chld_thm_cfg_parent_css() {
wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit(
get_template_directory_uri() ) . 'style.css', array( ) );
}
endif;
add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css', 10 );
function my_theme_enqueue_styles() {
$parent_style = 'tesseract-site-banner';
wp_enqueue_style( $parent_style,
get_template_directory_uri() . '/css/site-banner.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/site-banner1.css',
array( $parent_style, 'tt-easy-google-font-styles')
); }
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles',99999 );
Currently site-banner1.css is visible in the source code but it is not the last stylesheet to load and so the changes are not visible. The parent site-banner.css is still visible in the dev tools with the styles. By adding the last CSS id into the array can I force site-banner1.css to load after it, I think code is missing from the array but not sure what? If this is incorrect what is the way to force the sheet to load at the end of the queue?
I managed to fix the problem using wp_deregister_style:
<?php
if ( !defined( 'ABSPATH' ) ) exit;
if ( !function_exists( 'chld_thm_cfg_parent_css' ) ):
function chld_thm_cfg_parent_css() {
wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit(
get_template_directory_uri() ) . 'style.css', array( ) );
}
endif;
add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css', 10 );
add_action( 'wp_enqueue_scripts', 'load_alta_styles', 200 );
function load_alta_styles() {
wp_dequeue_style( 'tesseract-site-banner' );
wp_deregister_style( 'tesseract-site-banner' );
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() .
'/site-banner1.css' );
}
Related
I created two plugins for Wordpress. Both plugins have different scripts and stylesheets. To load this scripts I use this method:
class load_scripts{
function register_market(){
add_action( 'admin_enqueue_scripts', array($this, 'enqueue_admin_market') );
}
function enqueue_admin_market(){
wp_enqueue_style( 'pluginstyle', plugins_url( '/assets/backend-style.css', __FILE__ ) );
wp_enqueue_script( 'pluginscript', plugins_url( '/assets/backend-script.js', __FILE__ ) );
wp_enqueue_media();
}
}
if( class_exists( 'load_scripts')){
$load_scripts = new load_scripts();
$load_scripts->register_market();
}
Of course I used different function and class names.
Now the problem is if both plugins are activated the scripts are loaded from only one plugin.
I tried to do this, but does not work:
add_action( 'admin_enqueue_scripts', array($this, 'enqueue_admin_market'), 0 );
What can I do to solve this conflict?
Your issue lies on these two lines:
wp_enqueue_style( 'pluginstyle', plugins_url( '/assets/backend-style.css', __FILE__ ) );
wp_enqueue_script( 'pluginscript', plugins_url( '/assets/backend-script.js', __FILE__ ) );
Namely, you probably have 'pluginstyle' and 'pluginscript' as the handles in both your plugins. The $handle parameter should be unique in accordance with the wp_enqueue_style() and wp_enqueue_script() function references. For example:
Plugin 1:
function enqueue_admin_market(){
wp_enqueue_style( 'pluginstyle-1', plugins_url( '/assets/backend-style.css', __FILE__ ) );
wp_enqueue_script( 'pluginscript-1', plugins_url( '/assets/backend-script.js', __FILE__ ) );
wp_enqueue_media();
}
Plugin 2:
function enqueue_admin_market(){
wp_enqueue_style( 'pluginstyle-2', plugins_url( '/assets/backend-style.css', __FILE__ ) );
wp_enqueue_script( 'pluginscript-2', plugins_url( '/assets/backend-script.js', __FILE__ ) );
wp_enqueue_media();
}
I'm trying to develop a wordpress theme from scratch, but I have som problem with function.php. I want to add additional style scripts like bootstrap and animate.css, but the thing is that they are not loading with the "package" and when I check the links I get style.css before my css folder. If I remove style.css I can se my file in my browser. How do I solve this problem? To remove style.css from the links.
http://localhost/humlan/wp-content/themes/humlan/style.css/css/bootstrap.min.css?ver=3.0.3'
THIS IS CODE IN FUNCTION.PHP
/**
* Enqueue scripts and styles.
*/
function humlan_scripts() {
wp_enqueue_style( 'bootstrap.min', get_stylesheet_uri() . '/css/bootstrap.min.css',false,'3.0.3','all');
wp_enqueue_style( 'prettyPhoto', get_stylesheet_uri() . '/css/prettyPhoto.css',false,'1.1','all');
wp_enqueue_style( 'font-awesome.min', get_stylesheet_uri() . '/css/font-awesome.min.css',false,'1.1','all');
wp_enqueue_style( 'animate', get_stylesheet_uri() . '/css/animate.css',false,'1.1','all');
wp_enqueue_style( 'main', get_stylesheet_uri() . '/css/main.css',false,'1.1','all');
wp_enqueue_style( 'responsive', get_stylesheet_uri() . '/css/responsive.css',false,'1.1','all');
wp_enqueue_style( 'humlan-style', get_stylesheet_uri() );
wp_enqueue_script( 'humlan-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true );
wp_enqueue_script( 'humlan-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'humlan_scripts' );
Try This
function load_styles(){
wp_enqueue_script( 'jQuery-js', 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js');
wp_enqueue_script( 'bootstrap-js', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', array('jquery'), '3.3.7', true );
}
Instead of loading css from your server, use CDN links that are comparatively faster...
Use get_stylesheet_directory_uri() - as that returns the folder of your stylesheet. What you're using returns the URI of the actual stylesheet.
I'm trying to change the "read more" link in a child theme.
From the codex, I've added the following to the functions.php file of the parent theme (twentyseventeen)
// Replaces the excerpt "Read More" text by a link
function new_excerpt_more($more) {
global $post;
return ' <a class="moretag" href="'.
get_permalink($post->ID) . '"> Read the full article...</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');
...and it does what I'd like it to do.
However, I don't want it to be wiped out if the theme is ever updated.
So I've created a child-theme.
However when I add the code to the child theme functions.php file, it does not work.
My child-theme functions.php file looks like this:
<?php
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
// BEGIN ENQUEUE PARENT ACTION
// AUTO GENERATED - Do not modify or remove comment markers above or below:
if ( !function_exists( 'chld_thm_cfg_parent_css' ) ):
function chld_thm_cfg_parent_css() {
wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit( get_template_directory_uri() ) . 'style.css', array( ) );
}
endif;
add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css', 10 );
if ( !function_exists( 'child_theme_configurator_css' ) ):
function child_theme_configurator_css() {
wp_enqueue_style( 'chld_thm_cfg_separate', trailingslashit( get_stylesheet_directory_uri() ) . 'ctc-style.css', array( 'chld_thm_cfg_parent','twentyseventeen-style' ) );
}
endif;
add_action( 'wp_enqueue_scripts', 'child_theme_configurator_css' );
function my_scripts_method() {
wp_enqueue_script(
'custom-script',
get_stylesheet_directory_uri() . '/custom_script.js',
array( 'jquery' )
);
}
add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
// END ENQUEUE PARENT ACTION
// Replaces the excerpt "Read More" text by a link
function new_excerpt_more($more) {
global $post;
return ' <a class="moretag" href="'. get_permalink($post->ID) . '"> Read the full article...</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');
I was able to get this to work with some information from this question:
Wordpress functions.php child theme [Resolved]
In my child-theme functions PHP, I checked to see if the original twentyseventeen_excerpt_more() function has executed, and then give my alternative readmore() function a higher priority. With the higher priority (15), add_filter( 'excerpt_more', 'readmore', 15 ); my function runs first, and the original read more function is ignored in the parent theme.
This is what the function looks like in my child-theme functions.php file:
if ( ! function_exists ( 'twentyseventeen_excerpt_more' ) ) {
function readmore( $link ) {
if ( is_admin() ) {
return $link;
}
$link = sprintf( '<p class="link-more">%2$s</p>',
esc_url( get_permalink( get_the_ID() ) ),
/* translators: %s: Name of current post */
sprintf( __( '[Read More...]<span class="screen-reader-text"> "%s"</span>', 'twentyseventeen' ), get_the_title( get_the_ID() ) )
);
return ' … ' . $link;
}
add_filter( 'excerpt_more', 'readmore', 15 );
}
BTW, the above could also be inserted into a plugin .php file if you would prefer.
Read the wordpress codex several times and I was still unable to link the files so that my dropdown menu could work. Is there anything I need to do that is not in the functions.php?
<?php
function load_js() {
wp_enqueue_script( 'mytheme-jquery', get_template_directory_uri() . '/js/jquery-2.1.4.min.js', array( 'jquery' ) );
wp_enqueue_script( 'mytheme-bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', array( 'jquery' ) );
}
add_action( 'wp_enqueue_scripts', 'load_js' );
?>
I have a weird situation going on. I'm currently working on localhost. Wordpress seems to be enqueuing my stylesheet as a script. Below is a screenshot and and a snippet of the enqueue code. The stylesheet is also throwing errors in the console, as if being interpreted as a script.
if ( is_page_template( 'page-templates/fullpage-scroll-template.php' ) ) {
wp_register_script( 'fullpage-css', trailingslashit( get_template_directory_uri() ) . 'css/fullpage.css' );
wp_enqueue_script( 'fullpage-css' );
}
as prometheus pointed out there, it should be wp_enqueue_style NOT wp_enqueue_script
if ( is_page_template( 'page-templates/fullpage-scroll-template.php' ) ) {
wp_register_style( 'fullpage-css', trailingslashit( get_template_directory_uri() ) . 'css/fullpage.css' );
wp_enqueue_style( 'fullpage-css' );
}