Forums

Multiple add_action and add_filter on the same tag is not working for me (5 posts)

  1. daljirman
    Member
    Posted 1 year ago #

    Hello there,

    I'm creating a custom plugin that handles the way excerpts display. It cuts off the "[...]" found at the end of each excerpt as it adds Drop Cap effect to the beginning of the excerpt.

    Everything works well for me except that when I apply the action/filters to both of my functions one of them will work while the other is not working.

    For example the function that cuts the "[...]" off will work and the function that adds the drop cap effect will not work.

    Or the function that adds the drop cap effect will work or the other will not work.

    If I separate the two functions and make each a different plugin, the first activated plugin will work.

    So, how can I make both of them work at the same time on the excerpt, or is that impossible??

  2. Otto42
    Moderator
    Posted 1 year ago #

    Code, dude. Post the code that's giving you problems.

    We can't diagnose things in a vacuum.

  3. daljirman
    Member
    Posted 1 year ago #

    Never mind, I eventually came over the problem by assigning one function to all the jobs and everything is working as a magic now...

  4. Xiyangchou
    Member
    Posted 4 months ago #

    I would like to know your solution daljirman. Otto...maybe you could help me out. Here is my code so far. Each filter will work on its own, but I'm trying to get them both to operate at the same time.

    <?php
    // Youtube
    function wp_youtube() {
    $video = get_the_content();
    $video = preg_replace('#\[video\]http://www.youtube.com/watch\?v=(.*?)\[/video\]#i', '<object type="application/x-shockwave-flash" data="http://www.youtube-nocookie.com/v/\\1&rel=0"><param name="movie" value="http://www.youtube-nocookie.com/v/\\1&rel=0" /><param name="wmode" value="opaque" /></object>',$video);
    return $video; }
    function wp_youtube_filter() { return wp_youtube(); }
    $filter = wp_youtube_filter;
    
    // Google
    function wp_google() {
    $video = get_the_content();
    $video = preg_replace('#\[google\]http://video.google.com/\[/google\]#i','<p>Hello</p>',$video);
    return $video; }
    function wp_google_filter() { return wp_google(); }
    $filter = wp_google_filter;
    
    // excecute filter
    function all_video_filter() { return $filter; }
    add_filter('the_content', 'all_video_filter' );
    ?>
  5. Xiyangchou
    Member
    Posted 3 months ago #

    ok...you know what...this code bites and I'm a total noob...

Topic Closed

This topic has been closed to new replies.

About this Topic