Blank space at beginning of tag?

It looks like your site’s title is empty. Fill it out or try for example: add_filter( ‘wp_title’, function( $title ) { return trim( $title ); } ); to remove the blank space in front. For your setup, the following part of wp_title() is responsible for the blank space: $title = $prefix . implode( ” $sep … Read more

Stop Duplicating Terms in a Foreach Loop

I would tend to do this: $terms = array(); $terms_tags = wp_get_post_terms( $query->post->ID, array( ‘post_tag’ ) ); foreach ( $terms_tags as $term_tag ) { $terms[$term_tag->slug] = ‘<button class=”filter” data-filter=”.’.$term_tag->slug.’,”>’.$term_tag->name.'</button>’; } echo implode($terms,’, ‘); It leverages the fact that PHP does not allow duplicate array keys, and thus avoids the overhead of function calls. In your … Read more

How do I turn a shortcode into PHP code?

In general, inserting and executing shortcodes directly into templates files is not good idea and it is not what shortcodes are intented for. Instead, you should use the shortcode callback just like any other PHP function or template tag. For example, let’s imaging this shortcode: add_shortcode(‘someshortocode’, ‘someshortocode_callback’); function someshortocode_callback( $atts = array(), $content = null … Read more

the_author() not working outside the loop

I will answer my own question here. The reason the user information didn’t display is because the php tags need the author ID when used outside the loop. For instance the following tag: <?php the_author(); ?> Should be like this: <?php the_author_meta(‘display_name’, 1); ?> This is explain quite well here. Now the code works just … Read more

To echo or not to echo?

The main differences are: the first snippet has html inside php while the second one has php inside html. Both approaches are basically valid, both are fine. I would however always prefer (and recommend) to have php inside html because chances are that a third person / designer might have less difficulties in understanding the code … Read more

Why WordPress architecture is not pure object oriented and it don’t use MVC pattern? [closed]

WordPress as a project has extreme commitment to backwards compatibility. Whatever new things you add the old things need to work still. Whatever things you change still need to work in old way as well. So regardless of how WP started as non–MVC application, it cannot become one without retaining all of its non–MVC ways. … Read more