Tag Info

Hot answers tagged

7

This is an alternative approach to @kaiser answer, that I found pretty fine (+1 from me) but requires additional work to be used with core WP functions and it's per-se low integrated with template hierarchy. The approach I want to share is based on a single class (it's a stripped-down version from something I'm working on) that takes care of render data for ...


6

Basic separated data structures To pass around data, you normally utilize a Model (that's the "M" in "MVC"). Let's look at a very simple interface for data. Interfaces are just used as "Recipes" for our building blocks: namespace WeCodeMore\Package\Models; interface ArgsInterface { public function getID(); public function getLabel(); } Above is ...


5

Via using the dynamic_sidebar() you can change/edit the widgets in the widgets area of the appearance settings. If you use the_widget() you hard code it straight to template so you need to modify the code to change what is displayed. Both have their uses. Too many sidebars tend to clutter the widgets area, but is very good for users that don't want to mess ...


4

Simple answer, don't pass variables anywhere as it stinks of using global variables which is evil. From your example it seems like you are trying to do an early optimization, yet another evil ;) Use the wordpress API to get data which is stored in the DB and don't try to outsmart and optimize its usage as the API do more then just retrieving values and it ...


3

You can use PHP get method to process these variables. <?php if( $_GET['action'] == 'discussion' ) { ?> It's True. <?php } else { ?> It's False. <?php { ?>


2

You can use get_pages(); or get_posts(); or WP_Query to get a list of pages. They differ somewhat in details, so read up on that. But generally all of them should suffice, for you to achieve your goal. Just choose the best fitting one for your purpose. For getting pages by name or better title you can use: get_page_by_title() Or use: ...


2

the_widget() is used to display a specific widget outside of a sidebar. To be honest, this function serves no valuable purpose as you need to hard code the widget $instance parameters, this means that you will need to manually change the code every time you need to change something. So much for dynamica. It would just be easier to simply code a custom ...


2

Anyway, basically Hody_McGee gave the answer in his comment: You could use wp_localize_script(). As it states in the Codex: [wp_localize_script()] can be used to make any data available to your script that you can normally only get from the server side of WordPress. How do we do this? <?php add_action( 'wp_enqueue_scripts', 'register_scripts' ...


1

Ok, so the problem was that I was adding the variable outside the function. After some cleanup, code looks like this and it works! function roots_setup() { // Variables $header_type = get_field('header_type','options'); if (($header_type)=='brand-centered') { register_nav_menus(array( 'brand_centered_left' => __('Brand Centered Navigation (Left)', ...


1

An easy solution is to write a function to get the extra title. I use a static variable to keep the database calls to one only. Put this in your functions.php. function get_extra_title($post_id) { static $title = null; if ($title === null) { $title = get_post_meta($post_id, "_theme_extra_title", true) } return $title; } Outside ...


1

The problem is that wp_reset_postdata attempts to restore $post from the main $wp_query, but on post.php in admin, $post isn't populated from $wp_query, so wp_reset_postdata fails to restore it. The solution is to use get_posts and a foreach instead of WP_Query and the loop.


1

You need to get $current_cityinfo first. As in: $current_cityinfo = get_option('current_cityinfo'); Or add this code: global $current_cityinfo; above your return line.


1

You have to use single_product_large_thumbnail_size filter for Single Product page. something like: function custom_product_large_thumbnail_size() { return 'gallery'; } add_filter('single_product_large_thumbnail_size', 'custom_product_large_thumbnail_size');


1

If that is the sum of the code for that file then the only place near the bottom is that do_action-- do_action( 'shiroi_after_post_body_content' );-- which looks to be what you want. function test_new_action() { echo 'Howdy'; } add_action('shiroi_after_post_body_content','test_new_action'); Depending upon how this file is included there might be other ...


1

I haven't looked in detail at your code, but what strikes me is your open_csv method. You have the following lines return $attributes['file']; return $attributes['type']; As your method currently stands, it stops and returns the value of file right after setting the attributes. Here is what return does in php If called from within a function, theĀ ...


1

You should hook save_post instead of publish_post. publish_post only runs when a post is initially published and won't catch subsequent saves. Additionally, the publish_post hook passes parameters to your function and those should be used to retrieve info about the post being published rather get_the_content(), which only works when you're inside the ...


1

get_template_directory() gives you the path to the parent theme while get_stylesheet_directory() gives you the path to the child theme. Docs: https://codex.wordpress.org/Function_Reference/get_stylesheet_directory https://codex.wordpress.org/Function_Reference/get_template_directory


1

Lets start with your first code. If you add texts, captions etc. a shortcode will be generated: [caption] The function img_caption_shortcode() in wp-content/media.php is responsible to execute the shortcode. But this shortcode is only produced, when you use captions. Otherwise, it will be simply inserted the <a>- and <img>-Tag. who decides, what ...



Only top voted, non community-wiki answers of a minimum length are eligible