Localize strings for translation

Always keep in mind: your translators might need need to reorder all words. So you cannot insert dynamic values into translatable strings like you did here. Use sprintf() or printf() and placeholders instead: $string = _x( ‘This article has %s words to read’, ‘%s = number of words’, ‘your_textdomain’ ); printf( $string, number_format_i18n( str_word_count($post->post_content) ) … Read more

Problem only while using require_once() within functions.php

I noticed the URL of the custom Dashboard page is this… themes.php?page=functions-test.php Notice how the page is the name of my external functions in includes/functions-test.php. The problem is in this line, the one that refreshes the page just before the permission error… echo ‘<meta http-equiv=”refresh” content=”0;url=themes.php?page=functions.php&saved=true”>’; Now it seems so obvious. Look at the page … Read more

Create shortcode in Child Theme?

Shortcodes don’t ‘echo’, they need to ‘return’ something. So I guess it will work if you put your functions content between ob_start and ob_get_clean so you return everything inbetween: function yourfunction(){ ob_start(); /* insert here the code of your function */ $output = ob_get_clean(); return $output; }

Injecting a custom sql query into a page/theme

The hooks you are looking for can be found in the WordPress Codex WP_Query – Filters: Filters posts_distinct – Alters SQL ‘DISTINCTROW’ clause to the query that returns the post array. posts_groupby – Alters SQL ‘GROUP BY’ clause of the query that returns the post array. posts_join – Alters SQL ‘JOIN’ clause of the query … Read more

Order of stylesheets in child theme

The function wp_enqueue_style has the param $deps for depends. $deps (array) (optional) Array of handles of any stylesheet that this stylesheet depends on; stylesheets that must be loaded before this stylesheet. false if there are no dependencies. Default: array() Use this param to define the dependencies and you have an order. function blue_planet_scripts() { wp_enqueue_style( … Read more

How to use custom stylesheet only for a template in child theme

Try this: add_action( ‘wp_enqueue_scripts’, ‘my_custom_styles_function’, 100 ); function my_custom_styles_function(){ if (is_page_template(‘test-template.php’)) { wp_enqueue_style( ‘my-custom-css’, get_stylesheet_directory_uri() . ‘/custom-style.css’ ); } } wp_enqueue_scripts hook is used for including new stylesheet. Here template is test-template.php. Change it with your template. Stylesheet will only be included in your page template.