• hi,
    i’m new at WP Coding, i find it cool especailly with the plugin setup, so i do creat a plugin who will to easy my need to show my archives, so i creat one who used the php “str_replace”, it work perfectly whene i replace some words, but whene i put a template tag it dont
    her my code :
    ____________________
    <?php
    /*
    Plugin Name: Archives
    Plugin URI: https://agadirweb.com
    Description: Display the archives monthly or yearly.
    Version: 0.1
    Author: Hafsi Kamal
    Author URI: https://agadirweb.com
    */
    function monthly_get_archives() {
    print(‘
    <?php wp_get_archives(‘type=monthly&limit=12’); ?>
    ‘);
    }

    function my_function ($text) {
    $text = str_replace(‘###archives-monthly###’, monthly_get_archives(), $text);
    return $text;
    }
    add_filter(‘the_content’,’my_function’);
    ?>
    ____________________
    the word press declare an error in this lines with ***
    print(‘
    ***<?php wp_get_archives(‘type=monthly&limit=12’); ?>
    ‘);
    }
    thanks all for u r help

Viewing 6 replies - 1 through 6 (of 6 total)
  • because you did not escape the quotes \’

    Thread Starter taghaboy

    (@taghaboy)

    because you did not escape the quotes \’

    i do that but not working

    from what I looked at the code, you cant do that to wp_get_archives() because that function print stuffs out and not return you a value. You need to use object buffer(ob) to do it, https://php.net/ob_start

    Thread Starter taghaboy

    (@taghaboy)

    hello,
    really it’s so hard to me to understand all thos codos, i’m not really a pro in PHP but i still learning it, if possible pls , can ypu do a touche in that code.
    thanks

    ob_start();
    wp_get_archives('type=monthly&limit=12');
    $archives = ob_get_contents();
    ob_end_clean();

    Do your stuff on $archives.

    Thread Starter taghaboy

    (@taghaboy)

    Sir,still not understand yet, where i add that code… can u to provide me the complet code please.
    thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘probleme with my plugin – str_replace’ is closed to new replies.