Insert Ad Code in the Middle of a Post

This function inserts your ad code after the specified paragraph. add_filter(‘the_content’, ‘wpse_ad_content’); function wpse_ad_content($content) { if (!is_single()) return $content; $paragraphAfter = 2; //Enter number of paragraphs to display ad after. $content = explode(“</p>”, $content); $new_content=””; for ($i = 0; $i < count($content); $i++) { if ($i == $paragraphAfter) { $new_content.= ‘<div style=”width: 300px; height: 250px; … Read more

ajax live search for post title

Here is a working solution (tested as is) The HTML (could be part of page content) <input type=”text” name=”keyword” id=”keyword” onkeyup=”fetch()”></input> <div id=”datafetch”>Search results will appear here</div> The JavaScript ( goes to your theme’s functions.php ) // add the ajax fetch js add_action( ‘wp_footer’, ‘ajax_fetch’ ); function ajax_fetch() { ?> <script type=”text/javascript”> function fetch(){ jQuery.ajax({ … Read more

AJAX handler throws 400 (Bad request) – why?

in your html add `<input name=”action” type=”hidden” value=”test_function”/>` here “value” is your “action_name”. Your ajax call is incorect. Data should be url: “your php action script” data: $(html data).serialize(), About ajax first try to create ajax on your computer without wordpress. When you understand how ajax work try on WordPress.

wp_get_attachment_image returns different image size

Handle built in sizes right I wrote a class that handles all the different stuff for built in image sizes. To redefine the built in sizes, use an extended class (the upper file in the linked source) To unset a class and skip it’s useage completely, just set w & h to 0. http://static.steffenvogel.de/wp-content/uploads/2011/07/octocat_construction.gif Click … Read more

Disabling pingback and trackback notifications

To disable pingback and trackbacks, add this code to your functions.php file in your child theme: add_action( ‘pre_ping’, ‘wpse_190346_internal_pingbacks’ ); add_filter( ‘wp_headers’, ‘wpse_190346_x_pingback’); add_filter( ‘bloginfo_url’, ‘wpse_190346_pingback_url’) ; add_filter( ‘bloginfo’, ‘wpse_190346_pingback_url’) ; add_filter( ‘xmlrpc_enabled’, ‘__return_false’ ); add_filter( ‘xmlrpc_methods’, ‘wpse_190346_xmlrpc_methods’ ); function wpse_190346_internal_pingbacks( &$links ) { // Disable internal pingbacks foreach ( $links as $l => $link … Read more

Default content for a post in one category?

One possibility is this question/answer here by Jan Fabry, which asks for the default content in the process of creating the new post: Force category choice before creating new post? I ended up using a Quicktag as a way of easily getting the content into a post, and because the default content happened to be … Read more

current_cat_ancestor Alternatives

After fumbling around with this for a bit, I realized I needed this to work with custom taxonomies, not just regular categories. I unfortunately couldn’t use “all” of what either the solution I found or Tom did, so I ended up writing my own. As long as you specify a taxonomy arg, you should be … Read more