Home › Forums › General Issues › Archives Not Loading/Updating Stylesheet in Script › Reply To: Archives Not Loading/Updating Stylesheet in Script
Solved. Here are the steps I took:
I registered these options pages:
/** Creates ACF Options Pages **/
if( function_exists('acf_add_options_page') ) {
acf_add_options_sub_page(array(
'page_title' => 'Posts Style',
'menu_title' => 'Posts Stylesheet',
'parent_slug' => 'edit.php',
'capability' => 'manage_options'
));
acf_add_options_sub_page(array(
'page_title' => 'Portfolio Style',
'menu_title' => 'Portfolio Stylesheet',
'parent_slug' => 'edit.php?post_type=portfolio',
'capability' => 'manage_options'
));
acf_add_options_sub_page(array(
'page_title' => 'Careers Style',
'menu_title' => 'Careers Stylesheet',
'parent_slug' => 'edit.php?post_type=careers',
'capability' => 'manage_options'
));
}
I created my ACF select fields:
And they all share these dropdown values:
This code in the functions.php file works:
/** Enqueue Dynamic Stylesheet using ACF Field **/
function dynamic_style()
{
if (is_singular()) {
global $post;
$singular_css = get_field('singular_css', $post->ID);
wp_enqueue_style('singular_css', get_stylesheet_directory_uri(). $singular_css);
} elseif (is_home()) {
$posts_css = get_field('posts_css', 'option');
wp_enqueue_style('posts_css', get_stylesheet_directory_uri(). $posts_css);
} elseif (is_post_type_archive('portfolio')) {
$portfolio_css = get_field('portfolio_css', 'option');
wp_enqueue_style('portfolio_css', get_stylesheet_directory_uri(). $portfolio_css);
} elseif (is_post_type_archive('careers')) {
$careers_css = get_field('careers_css', 'option');
wp_enqueue_style('careers_css', get_stylesheet_directory_uri(). $careers_css);
} elseif (is_404()) {
wp_enqueue_style('white_css', get_stylesheet_directory_uri(). '/custom-css/white.css');
}
}
add_action('wp_enqueue_scripts', 'dynamic_style', 99);
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.