I just added a filter to the_title using the following code:
function my_filter($content) {
$content .= '<div class="meta">';
$content .= 'My filter';
$content .= '</div>';
return $content;
}
if(!is_single()){
add_filter('the_title', 'my_filter', 1);
}
What I noticed is the filter is also added in those titles which are used in the wp_nav_menu() .
I only want to display the filter after the title if the current page is not a single post page.
Try changing your code to remove the filter as well:
if(!is_single()){
add_filter('the_title', 'my_filter', 1);
}
else {
remove_filter('the_title', 'my_filter', 1);
}
My guess is that once the filter is added on a non-single page, it stays applied until removed.
http://codex.wordpress.org/Function_Reference/remove_filter
Related
Function and filter to display a player post titles:
function wpb_after_post_content($content){
if (is_single()) {
$id=get_the_ID();
$post_meta=get_post_meta(get_the_ID(), 'enclosure', TRUE);
$mp3=explode('.mp3',$post_meta);
$title=get_the_title();
if(count($mp3)>1)
{
$player = '<div class="post_player">' . do_shortcode('[fap_track url="'.trim($mp3[0]).'.mp3" title=url="'.$title.'" share="" cover="" meta="" layout="list" enqueue=no auto_enqueue=yes]')."</div>";
$content=$player.$content;
}
}
if (is_single()) {
$id=get_the_ID();
$post_meta=get_post_meta(get_the_ID(), 'enclosure', TRUE);
$mp3=explode('.mp3',$post_meta);
$title=get_the_title();
if(count($mp3)>1)
{
$player = '<div class="zoomsounds_player">'. do_shortcode('[zoomsounds_player source="'.trim($mp3[0]).'.mp3" play_in_footer_player="on" config="default" artistname="'.get_post_meta($id, 'arxiu_de_so', true).'" config="" ]');
/**if (wp_is_mobile())*/ {
if(get_post_meta($id, 'arxiu_de_so', true)!=""){
/** $player .= " <p id='arxiu_so'> Arxiu de so: ".get_post_meta($id, 'arxiu_de_so', true)."</p>";*/
/**$player .= '<span id="arxiuVal" style="opacity:1"> '.get_post_meta($id, 'arxiu_de_so', true).'</span>';*/
}
}
$player .="</div>";
$content=$player.$content;
}
}
return $content;
}
add_filter( "the_content", "wpb_after_post_content" );
The above code works fine with the_content filter and displays the player below the featured image. However, when I use this function with the the_title filter, the page doesn't load at all. The reason I want to use the_title is because I want the player to display above the featured image but below the post title.
Screenshot:-
This screenshot is to show that with the_content the player displays however it displays below post image.
Please have a look as below:
If you want to use the_title(), then you no need to pass the post_id in the the_title(), we have some params for the_title() if you want to add them like as below:
$before
(string) (Optional) Markup to prepend to the title.
Default value: ''
$after
(string) (Optional) Markup to append to the title.
Default value: ''
$echo
(bool) (Optional) Whether to echo or return the title. Default true for the echo.
Default value: true
If you want to use get_the_title(), then you must need to pass post_id inside the get_the_title($postId);
According to your code snippet, you must update your code with as below for get_the_title():
<?php
function wpb_after_post_content($content){
if (is_single()) {
$id=get_the_ID();
$post_meta=get_post_meta(get_the_ID(), 'enclosure', TRUE);
$mp3=explode('.mp3',$post_meta);
$title=get_the_title($id);
if(count($mp3)>1) {
$player = '<div class="post_player">' . do_shortcode('[fap_track url="'.trim($mp3[0]).'.mp3" title=url="'.$title.'" share="" cover="" meta="" layout="list" enqueue=no auto_enqueue=yes]')."</div>";
$content=$player.$content;
}
}
return $content;
}
add_filter( "the_content", "wpb_after_post_content" );
?>
And for the the_title(), you should update your code with as below:
<?php
function wpb_after_post_content($content){
if (is_single()) {
$id=get_the_ID();
$post_meta=get_post_meta(get_the_ID(), 'enclosure', TRUE);
$mp3=explode('.mp3',$post_meta);
$title=get_the_title();
if(count($mp3)>1)
{
$player = '<div class="post_player">' . do_shortcode('[fap_track url="'.trim($mp3[0]).'.mp3" title=url="'.the_title().'" share="" cover="" meta="" layout="list" enqueue=no auto_enqueue=yes]')."</div>";
$content=$player.$content;
}
}
return $content;
}
add_filter( "the_content", "wpb_after_post_content" );
?>
NOTE: You have not declared the title parameter in the zoomsounds_player shortcode so please pass and update accordingly.
I hope it would help you out.
I have created an options page in ACF Pro and Have added a image field called company logo. Now I want to remove the genesis site title. I have genesis removing the site title but when i add in the ACF call it does not work. If someone can take a look at what I have and give me some advice that would be great.
remove_action( 'genesis_site_title', 'genesis_seo_site_title' );
add_action( 'genesis_site_title', 'child_seo_site_title' );
/* Then add logo to header. */
function child_seo_site_title() {
$logo = get_field('company_logo', 'option');
if($logo) {
$output .= "<img src='". $logo['url']."' alt='". $logo['alt'] ."' />";
}
}
Should be simple but can seem to get it to work.
You're appending the image to an undefined variable, $output, and then doing nothing with it.
Output the image instead:
function child_seo_site_title() {
$logo = get_field( 'company_logo', 'option' );
if ( $logo ) {
echo '<img src="' . $logo['url'] . '" alt="' . $logo['alt'] . '" />';
}
}
I'm trying to use admin_footer_text in my plugin to add html into admin page. it works. but I've another plugin install that's using the same hook admin_footer_text. my plugin is overwriting the html code of previous one. I want it to append not to overwrite.
here is how I'm using the code
add_filter('admin_footer_text', 'my_footer_admin', 1);
function my_footer_admin($default){
ob_start();
echo 'some text';
$content = ob_get_clean();
return $content;
}
You need to do it like the following example
add_filter('admin_footer_text', 'my_footer_admin', 1);
function my_footer_admin( $default ) {
ob_start();
echo 'some text';
$content = ob_get_clean();
return $default $content;
}
I have some blog. In one of my category i have 500 posts. I need to insert one simply link on the top of all of this posts which are for example cat=5.
How can i do it using mysql?
Thanks in advance!
you don't need to do it in mysql, you can use a hook.
Something like that:
function append_content($content) {
global $post;
if (in_category( 5, $post )) {
$original = $content;
$content = "<div class=\"ikaz\">";
$content .= "hello all";
$content .= "</div>";
$content .= $original;
return $content;
}
}
add_filter( 'append_content', 'like_content' );
I am trying to add attachment gallery after the_content() but it is not moving to below the_content() but top of the_content()
I have set priority to 9999 and still not working. Any idea or suggestion please?
add_filter('the_content', 'admin_gallery_after_content', 9999);
function admin_gallery_after_content($content)
{
$admin_gallery = new q2a_rm_front;
$content .= $admin_gallery->rm_admin_gallery();
return $content;
}