Support

Account

Home Forums Add-ons Options Page Help with get_field values on Options Page

Helping

Help with get_field values on Options Page

  • Hi there,

    I’m having some issues on getting the values to display on my site from my Options Page. I have followed the tutorial here, and the options page and custom fields are set up correctly.

    The code also should be working fine, as it is working on another WP website. I’m basically migrating the same code and setup to another WP site. I have been researching forums but am still unable to debug the issue.

    The issue I’m having is:
    I have set up an options page so that I can select different colors in the cms. I have set up Color Picker in the custom fields. When the color is selected, it should change the color of the links and buttons on my site.

    However, no values are returning when I make the selection. I have attached a screenshot to show what is happening in the inspector. A snippet of my code is below:

    //Return value of the color for About page
    <?php
    $about_color = get_field(‘about_color’, ‘option’);
    ?>

    //Display the color of the link from the get_field value
    <style type=”text/css”>
    a {
    color:<?php echo $about_color; ?>;
    }
    </style>

    If anyone has encountered this issue before and has any insights/suggestions I would greatly appreciate it! Thanks!

  • How do you include your styles in the page? it doesn’t work in the style.css but you can implement custom styles by using a styles.php like this:

    function my_dymanic_styles(){
      $about_color = get_field('about_color', 'options');
    
      $custom_css = "
        a{ color:{$about_color};}
      ";
      
       return my_css_strip_whitespace($custom_css);
    }

    Put this in your functions.php

    function my_css_strip_whitespace($css){
    	  $replace = array(
    	    "#/\*.*?\*/#s" => "",  // Strip C style comments.
    	    "#\s\s+#"      => " ", // Strip excess whitespace.
    	  );
    	  $search = array_keys($replace);
    	  $css = preg_replace($search, $replace, $css);
    
    	  $replace = array(
    	    ": "  => ":",
    	    "; "  => ";",
    	    " {"  => "{",
    	    " }"  => "}",
    	    ", "  => ",",
    	    "{ "  => "{",
    	    ";}"  => "}", // Strip optional semicolons.
    	    ",\n" => ",", // Don't wrap multiple selectors.
    	    "\n}" => "}", // Don't wrap closing braces.
    	    "} "  => "}\n", // Put each rule on it's own line.
    	  );
    	  $search = array_keys($replace);
    	  $css = str_replace($search, $replace, $css);
    
    	  return trim($css);
    }
    /**
     * Dynamic Styles additions.
     */
    require get_template_directory() . '/inc/style.php'; //make sure you correct the directory and file path you use
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Help with get_field values on Options Page’ is closed to new replies.