Retrieve the template directory URI via global or get_template_directory_uri() every time?

I would stay stick to the function. PHP caches functions for speed and efficiency. In some situations, using a function is faster then using a variable. There are other benefits too – imagine if you changed the name of your variable – you would have to go and update every piece of code where it’s … Read more

Grab the first paragraph of each post

You can use this function: function get_first_paragraph(){ global $post; $str = wpautop( get_the_content() ); $str = substr( $str, 0, strpos( $str, ‘</p>’ ) + 4 ); $str = strip_tags($str, ‘<a><strong><em>’); return ‘<p>’ . $str . ‘</p>’; } and then call it in your loop with: <?php echo get_first_paragraph(); ?> The magic part your looking for … Read more

Make a custom theme translate-ready

To do it properly, you need to generate a valid .mo file and load the text domain in your theme functions.php: function wpse222346_localize_theme() { load_theme_textdomain( ‘your_theme_domain’, get_template_directory() . ‘/languages’ ); } add_action( ‘after_setup_theme’, ‘wpse222346_localize_theme’ ); You can check the WordPress Codex for more info on the load_theme_textdomain function: https://codex.wordpress.org/Function_Reference/load_theme_textdomain Then you would call the translatable … Read more

Snippet: Use classes instead of inline styles for text alignment

Note This answer was originally included in @bitstarr‘s question above and was included as a separate answer here to comply with WPSE’s Q&A model. Maybe someone else will have this issue and so i will share my solution here with you folks. function make_mce_awesome( $init ) { /* There are easier things than make ‘left/center/right … Read more

What is the best book to learn how to make themes for wordpress?

I would start with the Codex: WordPress Codex: Theme Development These two books are still current enough to remain great resources: Smashing WordPress Themes, Thord Daniel Hedengren Build Your Own Wicked WordPress Themes, Alan Cole, Jeffrey Way, et al These also have Theme applicability: Digging Into WordPress, Chris Coyier, Jeff Starr Professional WordPress Plugin Development, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)