Insert After Second Paragraph Without Tag?

I need to stress that I think this is going to be very unstable and you may not always get the results you want, but in simple cases this should work. $content = apply_filters(‘the_content’, get_the_content()); $content = explode(“</p>”, $content, 2); // var_dump($content); // debug echo $content[0].'</p>’; echo ‘<div>Extra Content</div>’; if (!empty($content[1])) { echo $content[1]; }

Show single post then all posts (with pagination)

Pagination does not work well will with secondary queries. First, the ordinary pagination functions depend upon the main query in the global variable $wp_query. They won’t work with secondary queries. There are already a number of questions here about that if you search the site. Second, trying to paginate secondary queries tends to result in … Read more

Possible to paginate on single.php?

I think the easiest implementation would be to put your infinite scroll in category.php, and then, either using Dashboard -> Settings -> Reading -> Posts per page, or via direct query modification, display one post per page. Otherwise, depending on how you’re implementing the infinite scroll, you could make use of next_post_link() and previous_post_link(), both … Read more

Problem with single-page for my custom post

Your code looks sound, so you should have a look at the code in your single.php template, as I suspect that there is something wrong in that template to why nothing is displayed. You should set debug to true in wp-config.php. This should help you locate your problem Secondly, your single-posttype.php is wrongly named. Your … Read more

WordPress Single Conditional for Search Page

You could hook into the the_permalink filter and check for is_search() to conditionally modify the URLs of your search results to include some additional parameters that your single.php then checks for. Something like this (may require tinkering): add_filter( ‘the_permalink’, ‘wpse155331_the_permalink’ ); function wpse155331_the_permalink( $url ) { if ( is_search() ) { $url = add_query_arg( array( … Read more

Disable single pages and archives and keep preview

You can redirect, when someone tries to see the archive or the single of your custom post type, just redirect them to another page, just put this in your functions.php add_action( ‘template_redirect’, ‘theme_redirects’, 99 ); function theme_redirects() { if ( is_post_type_archive( ‘post_type_slug’ ) || is_singular( ‘post_type_slug’ ) ) { wp_redirect( ‘my_url’ ); die(); } } … Read more

How do I show google ads between post content?

You can use a shortcode or the_content filter. I think the_content filter is better because your don’t introduce any string in your post, so the content can be exported and used in another platforms if needed. For emxample, for show a block of adsense after the first parragraph: add_filter( ‘the_content’, ‘tbn_ads_inside_content’ ); function tbn_ads_inside_content( $content … Read more

Problem getting single_template filter to work – I want to serve a different single.php file for posts in a certain category

The problem was that the remove_filter function wasn’t working. Apparently this is not uncommon from what I’ve read. I tried testing it with different priorities (1, 9, 20, 999), but there was no difference. So my filter in the child theme and the filter I was trying to remove from the parent theme both had … Read more

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