Add code only for blog posts

It’s just that you got it a bit wrong – it’s actually if(is_single()) (not singular). If you want to address pages in general (not posts I assume), you would use if(is_page()) . If you need to address a specific page you could use its ID like so if(is_page(13)) where 13 would be the ID of … Read more

Display post from a category

I think that when you are filtering, you are using an onpage action that hides what is not on the category clicked (done with JavaScript, usually with jQuery), and when you go to another page, you are getting a new page from the server, so your filter disappear. I think that this behaviour is ok, … Read more

conditionally load a default static image if image metabox has no value

According to the get_post_meta() function reference in the WordPress Codex, “If there is nothing to return the function will return an empty array unless $single has been set to true, in which case an empty string is returned.” That means we can use ternary operators to check whether get_post_meta() returns an empty string, and if … Read more

News and Featured image

Some of the code you have in here is really outdated and has been deprecated for quite some time. I am going to use updated code so that it’s more useful to those who will stumble on this thread. <div class=”news_item”> <?php $posts = get_posts( ‘numberposts=2&order=DESC&orderby=post_title&category_name=news’ ); foreach ( $posts as $post ) : setup_postdata($post); … Read more

Add specific content after specific text in every post

I think you should use post-thumbnails In your functions.php file This function will give you access to add image on each post you want to add am image //And post featured images function add_featured_image(){ add_theme_support(‘post-thumbnails’); } add_action(“after_setup_theme”, “add_featured_image”); After adding that function in your functions.php, now you can access the functionality in admin dashboard. By … Read more

WordPress upload images not displaying

For a quick solution you can download the WordPress plugin photo-gallery https://wordpress.org/plugins/photo-gallery/. Once it’s installed and activated you hover your mouse over Photo Gallery in your WordPress Dashboard and click Add Galleries/images. Add a new picture or many pictures in a new gallery and save. When it’s done simply hover your mouse over Photo Gallery … Read more

Adding a “Word” in php code

any word (html) you put between the single quotes will be echoed when you echo $output. so you can do this: $output .= ‘<div class=”dhvc-woo-view”>View: ‘; $output .= get_post_meta($post->ID, ‘pageview’, true); $output .= ‘</div>’; or $output .= ‘<div class=”dhvc-woo-view”>’; $output .= ‘View: ‘; $output .= get_post_meta($post->ID, ‘pageview’, true); $output .= ‘</div>’; it’s the same.

Non-array argument in array_merge()-function [closed]

Just make sure it’s definitely an array before you try to merge it: function minevalg_hent_innstillinger() { $defaults = array(); // define this somewhere; reference it here if ( is_array( $options = get_option( ‘minevalg’ ) ) ) $options = array_merge( $defaults, $options ); else $options = $defaults; return $options; }