How to add an alternative style sheet as a theme option?
You’re trying to execute PHP in a string – you just need: get_template_directory_uri() . “https://wordpress.stackexchange.com/” . get_theme_mod( ‘posts’, ‘style.css’ ),
You’re trying to execute PHP in a string – you just need: get_template_directory_uri() . “https://wordpress.stackexchange.com/” . get_theme_mod( ‘posts’, ‘style.css’ ),
The better, cleaner solution would be not to use custom page templates to define page layouts*, but rather to use custom post meta to define page layouts. To implement: Create a Theme Option for Default static page layout, that includes all possible page layout options Create a _page_layout custom post meta for Page Layout, that … Read more
You want to manipulate and return the same input you have coming into the function. In your case that is $input. That is how filters work. function add_validation( $input ) { // here I want to add some validation for a simple field named ‘example’ if ( isset( $input[‘example’] ) && !empty( $input[‘example’] ) ) … Read more
So this goes in your themes functions.php file. This adds a metabox on the right side of your editscreen within posts called “Enable Post Views on this Post”: // Hook into WordPress add_action( ‘admin_init’, ‘add_custom_metabox’ ); add_action( ‘save_post’, ‘wpse_16722_save_post_views_value’ ); /** * Add meta box */ function add_custom_metabox() { add_meta_box( ‘enable_post_views’, __( ‘Enable Post Views … Read more
It’s not entirely clear what you are referring to here. Judging from your code theme_path looks like a constant. Usually when supplying/printing links to theme assets you would use get_bloginfo(‘key’) with one of the keys template_directory or stylesheet_directory. Basically the latter will point at the child theme and the first to the parent theme if … Read more
I realised I didn’t fully understand the link() function; now I realise that it links the control to the proper setting, making it problematic trying to point multiple controls to one setting. I modified my original function to instead add a hidden input that will hold my final value, along with the checkboxes. I then … Read more
vote_header_options_callback() is declared twice ! Trying to declare the same function name twice will cause a fatal PHP error. Give another name to your function.
Yes it is. But no by default. But it’s pretty easy to do it yourself. You can do it in 2 ways: 1. In single.php template file Just add if statement and use get_template_part function to load selected template. So your single.php file could look like this: <?php if ( isset($_GET[‘template’]) ) { switch ($_GET[‘template’]) … Read more
All options with autoload = yes (default) are fetched very early in one query. So the number of options does affect performance only marginally. Split options if you don’t need everything on every page load. With … add_option( ‘option_name’, ‘option_value’, ”, ‘no’ ); … you can set options that aren’t loaded before you actually call … Read more
Use wp_localize_script: wp_enqueue_script(‘YOUR_SCRIPT_HANDLE’); $object = array( ‘zoom’ => get_option(‘map_zoom’), ‘longitude’ => get_option(‘map_longitude’), ‘latitude’ => get_option(‘map_latitude’), ); wp_localize_script(‘YOUR_SCRIPT_HANDLE’, ‘JSObject’, $object); And then use it in your JS file like JSObject.zoom and the like.